Skip to main content

Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

Filter by
Sorted by
Tagged with
0 votes
0 answers
45 views

1D FDTD simulation of plane wave propagation and the Courant stability condition

I'm currently trying to simulate a simple case of wave propagation in free space before adding in more complexities, and already I'm stumped. I understand the Courant stability condition. However, I ...
Jerry Y's user avatar
4 votes
3 answers
134 views

Is there any matlab built-in function or libraries to calculate $\frac{d(\ln A)}{dA}$?

we can first conduct spectral decomposition of an positive definite isotropic tensor $A$ and then we can define $\ln(A)$, then we can define the frechet derivative of it, but how to calculate this in ...
YuerWu's user avatar
  • 191
2 votes
0 answers
58 views

2D cavity flow: Adding zero Dirichlet condition to the top boundary leads to NAN

I am following this guide to create a simple cfd solver for incompressible 2D fluid in a square cavity. The following Matlab code sample from the guide creates a Laplacian (coefficient) matrix with ...
Lit_try's user avatar
  • 21
0 votes
0 answers
38 views

A plane or surface passing through two surfaces in MATLAB

I have just been able to plot several surfaces using the code below. What I want is a plane or a surface that connects the black and yellow region in the output of the code below: ...
vidyarthi's user avatar
  • 111
2 votes
1 answer
68 views

What would be the right approach to numerically integrate in MATLAB an improper integral with Bessel function?

I have an improper integral which contains Bessel functions, Cosine term as well as a rapidly decreasing exponential term. This is the integral: $$\frac{1}{2\alpha}\int_{0}^{\infty}e^{-\frac{\xi^2}{4\...
ishan_ae's user avatar
1 vote
1 answer
76 views

'eigs()' in Matlab gives inaccurate eigenvector when only several eigenvalues are calculated

I would like to report an issue which may be interesting in computational physics. Sometimes, to save time and memory, we use eigs() to calculate the first several ...
basic nutshell's user avatar
0 votes
0 answers
53 views

Prof A. Stanoyevitch's finite difference based PDE matlab code

Where can one find Prof A. Stanoyevitch's finite difference based PDE matlab code? They have a book on such a topic but can't find the accompanying code. Is it well received? It's not commonly talked ...
feynman's user avatar
  • 317
1 vote
1 answer
105 views

Educational Purpose: How to synchronize chaotic systems

The graph plots the X coordinate of the synchronized Lorenz chaotic system. I am self learning by reading research articles on how to synchronize identical chaotic systems. But as seen from the figure,...
Sm1's user avatar
  • 119
0 votes
1 answer
95 views

Prof Lawrence Shampine's hpde matlab code

Where can one find Prof Lawrence Shampine's hpde matlab code? Is it well received? It's not commonly talked about.
feynman's user avatar
  • 317
0 votes
0 answers
30 views

How to stop loops or close figures in live scripts in matlab

I wanna use matlab live scripts to run a loop updating an animation because this will allow to playback the animation. In the normal command window or m files one can use uicontrol to stop loops or ...
feynman's user avatar
  • 317
0 votes
1 answer
69 views

ode23, 45, 15s, 15i in matlab for conservative ODEs

Which of ode23, 45, 15s, 15i in matlab are dissipative or anti-dissipative for conservative ODEs? Do they STAY dissipative or anti-dissipative for ALL conservative ODEs nor not? If not, what about for ...
feynman's user avatar
  • 317
1 vote
1 answer
79 views

Multivariable Newton's method for-loop

I am struggling with an assignment concerning Newton's method. We are to approximate 3 intersection points using intersecting circle coordinates P1, P2 and P3, using Newton's method. And I can do that ...
rawestan's user avatar
0 votes
1 answer
86 views

shooting method to compute the interface shape

I am trying to use a shooting method to compute the shape of liquid-gas interface given by the following differential equation: $$ \frac{d^2 \theta}{ds^2} = \frac{f(\theta)}{h(h + 3\lambda)} $$ with $\...
Sthavishtha Bhopalam's user avatar
0 votes
0 answers
61 views

Help with inferring Network topology from Spectral templates

I am trying to use matlab and YALMIP to solve a graph learning problem of recovering eigenvalues from the eigenvectors of the covariance of sampled graph signal data. This is to implement the ...
user86422's user avatar
1 vote
1 answer
122 views

Step size constraint in Euler backward

I am dealing with an assignment in MATLAB. It has to do with 'self-driving' cars which are driving in-front/behind eachother. Assuming M cars on a single-lane road, each car adjusts its speed based on ...
user46892's user avatar
0 votes
1 answer
89 views

How to plot the power spectrum

I have an array of data whose columns are solution vectors to a system of ODEs at a specific time. I want to plot the power spectrum of a solution at a specific time, but when I attempt this I get ...
KZ-Spectra's user avatar
4 votes
0 answers
126 views

FVM for non-regular domain with triangular mesh

Setup The 1D convection-diffusion equation is given by: \begin{equation}\tag{1} \frac{\partial u}{\partial t} + v \frac{\partial u}{\partial x} - \mu \frac{\partial^2 u}{\partial x^2} = 0, \end{...
VIVID's user avatar
  • 91
1 vote
1 answer
99 views

enough conditions to check that a matrix doesn't have Cholesky factorization while factorizing it

I wrote this code to find Cholesky factorization of a symmetric positive definite matrix in MatLab: ...
Ferran Gonzalez's user avatar
9 votes
3 answers
3k views

More stable algorithm to calculate `sqrt(a^2 + b^2) - abs(a)` in MatLab

Suppose we want to calculate $\sqrt{a^2+b^2}-|a|$ in MatLab. Using sqrt(a^2 + b^2) - abs(a) will have some problems: If a or <...
Ferran Gonzalez's user avatar
1 vote
0 answers
102 views

Method of lines for a mixed PDE

I am trying to solve the following PDE using the method of lines to discretize space, and then solve it as system of ODEs at each point in space using ODE15s: subject to and initial condition $w(z,t=...
Zoe's user avatar
  • 11
2 votes
0 answers
74 views

Complex matrix logarithm discontinuity by solving inverse Fourier integral by alternative method to FFT

NOTE: This code is a piece of code I am using for a master's thesis, so I do not expect someone to do the work for me, but I gladly accept suggestions of any kind. However, I am trying to get the ...
SimoPape's user avatar
0 votes
1 answer
91 views

How can I find the current for a nonlinear electrical circuit using the Shockley equation, in Octave?

For this electrical circuit: The voltage $ V_D $ can be found by solving a nonlinear equation: $$ \frac{V_{DD}}{R} - \frac{V_D}{R} - I_se^{V_D/V_T} = 0 $$ In this example, let $R=1000$, $V_T = 0.025$,...
Astor Florida's user avatar
2 votes
1 answer
198 views

Using Sundials CVODE in MATLAB

I'm currently using ode15s to solve a set of stiff differential equations. I am trying to use the MATLAB profiler to understand the section of the ode solver code which calls BLAS routines. Since the ...
Natasha's user avatar
  • 433
1 vote
2 answers
147 views

Matlab eigs function with function handle

I am reading through the documentation of matlab function eigs specifically the function handle input version. Here it is: https://www.mathworks.com/help/matlab/ref/...
user8469759's user avatar
2 votes
0 answers
54 views

In electromagnetic simulation, how much does the feed model impact an antenna's directivity performance and E-field phase readings?

Question: How much would a simplified feed model in an EM simulation alter an antenna's directivity and the E-field phase reading when compared to using a more complicated/realistic feed model? I am ...
Xingda Chen's user avatar
4 votes
2 answers
251 views

Reordering eigenvalues in Schur factorization - MATLAB ordschur and LAPACK dtrsen not producing the same results

Disclaimer: I previously posted this on SO, but though it would be more relevant for scicomp. The original post has been deleted. I have been trying to recreate the functionality provided by MATLABs <...
two_Thomas's user avatar
0 votes
0 answers
79 views

Appropriate values for fluid-structure interaction model using finite element method in MATLAB

I'm having a program to compute the solution for a fluid-structure interaction model (blood and blood vessel walls) using FEM in MATLAB. The program is running fine but the function that I'm ...
AgentOrange's user avatar
1 vote
0 answers
91 views

Optimal Krylov subspace dimension and iteration limits for eigs

When using the eigs function in MATLAB, which is based off of ARPACK, one can manually modify the maximal dimension of the constructed Krylov subspaces, the maximum iteration counts, and the error ...
user45844's user avatar
0 votes
0 answers
81 views

How to get damping matrix for structural model in FE analysis

I need to implement in C a method of obtaining transient solution of damped FE models based on modal results for a structural model (imported CAD geometry) defined with hysteretic (structural) damping....
Piotr's user avatar
  • 1
0 votes
1 answer
46 views

'Integral2' error in MATLAB for invalid integrand

Here is the code that I am trying to run: ...
vidyarthi's user avatar
  • 111
0 votes
2 answers
104 views

How to remove triangles in a hollow hemisphere shape?

So I have this code where I am designing a hollow hemispherical shape and I want to create a 3D volume to input it into FEBio software. I am using delaunay triangulation for meshing. But the problem ...
dazemood's user avatar
3 votes
1 answer
387 views

Generalized eigenvalue problem for large, potentially ill-conditioned systems

Say that I have a generalized eigenvalue problem of the form $$Ax=\lambda Bx.$$ Using MATLAB, some naive ways that one may solve this is by either directly inverting $B$ then applying the ...
user45844's user avatar
0 votes
0 answers
62 views

Plot 2D piecewise function in MATLAB

I'm trying to use this method Plot 2D piecewise constant in matlab in a finite elements mesh for my data. However, I have problems with the values of n1, n2 and n3. I guess this is why it doesn't show ...
AgentOrange's user avatar
0 votes
2 answers
171 views

Rotation of Higher order Tensors

I have a $D$-way tensor of dimensions $n\times n \times \dots \times n$ $(D)$- times. I want to sum the First vectors in all directions. For example, let $\boldsymbol{H}$ is 3-way tensor of dimensions ...
Neuling's user avatar
  • 35
3 votes
3 answers
206 views

Unable to calculate binomial coefficients correctly in matlab

I tried to compute the value of the following expression in Matlab: $$ 2^l\sum_{i=0}^{n-1}{N\choose i}\varepsilon^i(1-\varepsilon)^{N-i} $$ where $N=16272$, $n=499$, $l=107$, $\varepsilon=0.02$. I ...
Alex Cage's user avatar
1 vote
0 answers
62 views

Need help implementing finite difference Beam Propagation Method to Solve 2-D Helmholtz equation

I am trying to implement beam propagtion method in a two-dimensional lattice to solve Helmholtz equation by following the scheme given this paper. I am using Matlab for implementation. The expected ...
Yashab Yadav's user avatar
3 votes
1 answer
188 views

Numerical scheme for the level set equation that solves inverse mean curvature flow problems

I am considering the problem of simulating the evolution of an interface given as a curve in 2D (or surface in 3D) that evolves according to a velocity specified at the interface of the form: $$\vec{v}...
B0bby31's user avatar
  • 33
0 votes
1 answer
175 views

How do I use pdepe for a first order parabolic PDE with only one boundary condition?

I am trying to use Matlab's pdepe.m to solve the first order parabolic PDE $$\frac{\partial u}{\partial x}+\frac{\partial u}{\partial x}=x$$ I have not had trouble coding the argument of pdepe @pdefun:...
Walden Marshall's user avatar
5 votes
1 answer
175 views

Eigenvalues of diagonal plus rank-one

I need to compute an eigendecomposition of an $n\times n$ matrix $$ D + c vv^\top = Q\Lambda Q^\top \tag{1} $$ in MATLAB, where $D$ is a real diagonal matrix, $c$ is a scalar, and $v$ is a real vector....
eepperly16's user avatar
1 vote
0 answers
43 views

Sampling points from space based on known density

I have a problem where I heavily need to restrict the number of points at which I sample a function based on the values of a different function. I have two functions: $f:{\mathbb{R}\times [0,\infty)\...
blockchain187's user avatar
0 votes
0 answers
81 views

Best approach to solve this system of equations?

I have the following 1D (in space, that is) system of equations I would like to solve: \begin{equation} \rho_{fs}\frac{\partial x_{fs}}{\partial t} = h_m\left(W_a - W_{fs}\right) - D_{eff}\left(\...
HVdB's user avatar
  • 9
0 votes
0 answers
44 views

Model the water vapor fraction of a humid air inside a tower

I am going to model the moisture air inside an energy tower, therefore. I formulated the following equation to calculate the fraction of water vapor, Y in the moist air, where $\rho_w$ is the water ...
TMW's user avatar
  • 11
1 vote
0 answers
126 views

Discrete laplacian 9 point

I am trying to write a code for 9 point discrete laplacian. I would like to write a matrix and solve the linear system $AU=F$ with gradient conjugate method. I wrote the matrix this way ...
Cristie's user avatar
  • 41
3 votes
1 answer
130 views

Upwind scheme with periodic conditions

I am struggling with this assignment. I have to write an upwind scheme for the following PDE: $$u_t+a Du=0 \quad\mathrm{on}\;(-1,3)$$ $a$ is said to be positive, the initial condition is $\sin(2\pi x)$...
Cristie's user avatar
  • 41
0 votes
1 answer
217 views

Solve discontinuous ODE with lsode

I am trying to solve a discontinuous ODE using the lsode solver. I tried setting the t_crit parameter to specify the time where the discontinuity is present, but it ...
Bruno's user avatar
  • 101
2 votes
1 answer
69 views

Solving constrained odes's using inbuilt solvers in Matlab/Octave

I would like to solve a set of coupled second order differential equations using inbuilt Matlab/Octave subroutines. These equations arise when trying to model sliding of mass ($m_2$) over a wedge of ...
Salil S. Kulkarni's user avatar
0 votes
1 answer
236 views

How to speed up sparse matrix index operation in Matlab?

I need to create spare matrices with variable elements. Unfortunately, sparse matrix index operations are very slow. Is there any way to speed up the process? Maybe there are some tricks that I don't ...
Kim's user avatar
  • 21
0 votes
1 answer
65 views

Numerical solution of PDE with uniform initial condition

I have a PDE like this $$ \frac{\partial h}{\partial t} = \bigg(\frac{\dot{L}}{L}\bigg)x\frac{\partial h}{\partial x} - \alpha\bigg[h^3\frac{\partial^3 h}{\partial x^3}\bigg] $$ With boundary and ...
dazemood's user avatar
1 vote
0 answers
212 views

Magnetic field simulation for "quasi-solenoid" - Where to start?

I would kindly ask you which (preferably free) programs / codes do you suggest for the numerical simulation of the problem described below. I am not asking for the full solution, but just want to ...
t387's user avatar
  • 11
3 votes
2 answers
953 views

My Complex Matrix SVD is Correct according to rule A = USV' but Wrong according to Matlab or any linear algebra library

I am working on Singular Value Decomposition for complex matrices. I implemented One Sided Jacobi algorithm. It gives exactly the same result as the svd function in Matlab for the real matrices. ...
Emir evcil's user avatar

1
2 3 4 5
17