Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

157 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
0answers
338 views

How to solve a nonlinear diffusion equation?

Consider a thin film with a perpendicular applied magnetic field $H_a$ in $z$-axis. The nonlocal relation between $H_a$, the self-field $H_\text{self}$ (generated by the eddy current $J$) and the ...
1
vote
0answers
2k views

How to solve an ode with stochastic time-dependent input

I am trying to repeat an example I found in a paper. I have to solve this ODE: $25 \ddot{x} + 15 \dot{x} + 330000 x = p(t)$ where $p(t)$ is a white noise sequence band-limited into the 10-25 Hz ...
1
vote
0answers
351 views

Optimizing rank computation for very large sparse matrices

I have a sparse matrix such as ...
1
vote
0answers
2k views

Piecewise linear approximation of an experimental data curve. Knots position constrained

I need to fit a curve, obtained from experimental data, with a piecewise linear model (4 knots and therefore 3 lines). I tried using the MATLAB function ...
1
vote
0answers
993 views

algorithm Matlab function 'stream2' and 'stream3' use to compute streamline

Can anyone explain how the MATLAB functions: stream2(x,y,z,u,v,startx,starty) and stream3(x,y,z,u,v,startx,starty) compute stream lines from vector data u and v? In the stream2.m file, it calls the ...
1
vote
0answers
2k views

The solution found by the optimization function when exitflag is negative

I'm using Matlab's fmincon to solve a constrained nonlinear optimization for varying sets of parameters in the objective function. I have 2 parameters and have 400 unique combination of these 2 ...
1
vote
0answers
262 views

Generating start point in a systematic manner for fmincon

I'm trying to generate start points for my optimization problem in Matlab. At this point Im not worried about feasibility but only a fast way to generate the points from which I could test the ...
1
vote
0answers
232 views

Generating Hessian of the Lagrangian with dynamic number of nonlinear constraints in Fmincon

I'm using interior point algorithm for solving a nonlinear optimization problem and want to provide Hessian of the Lagrangian as part of fmincon to speed up the process (running couple of thousand ...
1
vote
0answers
761 views

Fast way to compute barycentric lagrange interpolation

Is there any fast way to compute the barycentric Lagrange interpolation using matlab? something more faster than using repmat instead of for loops
1
vote
0answers
2k views

Simulink PDE (MATLAB)

I need to build a system in Simulink that solves a PDE, but I can't find any literature or books where it is described how to do it (especially any stuff according to modeling PDE in Simulink). ...
1
vote
0answers
223 views

Sign or cardinality constraint when solving for sparse signal

I'm currently learning about using linear and semidefinite programming to find sparse solutions to problems. In particular, finding sparse solutions where the sampling functions are sinusoidal (...
1
vote
0answers
364 views

features recognition & reconstruction of 3d mesh delaunay matlab

I managed to display the coordinates of x,y and z into a 3D mesh by using delaunay function. The coordinates are in .obj format actually and i have read it into matrix form. Now, i would like to ...
0
votes
0answers
39 views

Path constraints for state variables - fmincon, ODE45

My problem lies in constraining state variables (look for 23,24,25). I am currently using ODE45 to solve equations and fmincon to find best control variable.How would you go about solving this? Here ...
0
votes
0answers
51 views

Can I get a symbolic solution for these coupled ODEs?

I found this IPython notebook called ‘Roller Coaster’ from", "numfys.net, where they model the movement of a ball over a path described by a third-degree polynomial $y(x)$ with slope $\...
0
votes
0answers
36 views

Using event function to shift between 2 sets of ODE

I have a bunch of ODEs I am trying to solve using ode45 in MATLAB. I have hidden the details of the equations to keep it simple (so as to build a general algorithm)! \[\frac{dR}{dt}= F_{1}(R,N) \quad\...
0
votes
0answers
78 views

Error $L_{2}$ convergence in Finite Element for Poisson Equation

I have written a Matlab code to solve the equation $-u'' = f$ with conditions $u(0) = u'(1) = 0$ on the domain $x \in [0,1]$. I tested the code with $f(x) = -2, \forall x\in [0,1]$. I check the plot ...
0
votes
1answer
73 views

Reason behind different outputs for Fast Fourier Transform in Numpy and Matlab

Here is the output of Numpy np.fft.ifft([0, 4, 0, 0]) array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) # may vary Here is the output of Matlab ...
0
votes
0answers
19 views

Improve code of logarithmic quantizer

I am implementing a logarithmic quantizer which is defined as follows: $$ q(u) = \begin{cases} u_i , \frac{u_i}{1+\delta} < u < \frac{u_i}{1-\delta} \\ 0 , 0 \leq u \leq \frac{u_o}{1+\delta} \\ -...
0
votes
0answers
37 views

Calling User defined Matlab Functions in Python with Matlab.engine API

I am trying to combine Matlab and python scripts and figure out if I can achieve a better solution in terms of the solver-runtime. A very simple optimization problem is used just for now. But I got in ...
0
votes
0answers
34 views

Estimating the Jacobian in Harmonic Balance Method

I am trying to solve a set of ODEs using the Harmonic Balance method. In order to do this, I need to compute the Jacobian of the set of equations. However I am very confused regarding the dimensions ...
0
votes
0answers
104 views

“This DAE appears to be of index greater than 1” daeic12 (line76) error code

Hi I am trying to solve a set of pde converted into ODE and DAE using central finite difference method. I have used the MATLAB 'solve' command to determine the coefficients of fictitious nodes for ...
0
votes
0answers
144 views

Problem with solving coupled ODE and DAE equations with mass matrix (Error using daeic12 (line 77) This DAE appears to be of index greater than 1)

I am trying to solve 6 ODE equations coupled with 1 DAE one. The ODE equations have been discritized in space domain and ode15s MATLAB solver is used to solve the equations in time domain. I have ...
0
votes
0answers
19 views

3d surface image for given datasets

I have some data that looks like as follows x-cor y-cor z-cor 0.02 0.0251 0.02 0.01 0.0257 0.02 0.014 0.02 0.03 0.023 0.003 0.05 0.013 0.002 0.77 .................... .................... ...
0
votes
0answers
32 views

How to describe function convergence and function tolerance for numerical root-finding?

I'm currently doing some practice problems on root-finding and am writing up some notes / comments on my code. In my solver code, if my function value is below the tolerance that I've set, should I ...
0
votes
0answers
60 views

Non-linear differential equation

I have this equation $$y\left(\dot y^2+1\right)=m + \Lambda y^3,$$ where $\Lambda=1.1\cdot 10^{-52} $ (Cosmological constant). I want to get the graph of the solution of this equation (2-parametric ...
0
votes
0answers
34 views

Simulating the response of nonlinear system with stiff differential equations

I want to simulate the response of a nonlinear system given in the following form: $$ \dot{x_1} = f_1(\bar{x_1})+g_1(\bar{x_1})x_2, \ x_1(0) = 0.2 $$ $$ \dot{x_2} = f_2(\bar{x_2})+g_2(\bar{x_2})x_3, \...
0
votes
0answers
72 views

Comparison of diffusion time - theoretical value vs computed

This is a follow up to my previous post I've been trying to compare the diffusion time obtained from theoretical derivation(answered in my previous post) and what is obtained computationally, for a ...
0
votes
0answers
64 views

Fast algorithm for computing lower mode shapes and natural frequencies in MATLAB using sparse stiffness and mass matrices

I am looking for a fast algorithm for computing eigenvalues and eigenvectors from sparse stiffness and mass matrices in MATLAB. The eig(K, M) doesn't work with ...
0
votes
0answers
62 views

Can't plot correctly precession of perihelion of Mercury in MATLAB using ode45 or ode23

I was trying to plot precession of perihelion of Mercury using matlab. For this I am following a book Computational Physics by Nicholas J. Giordano and Hisao Nakanishi 2nd Edition. In that book ...
0
votes
0answers
53 views

Simulating flow in a branched pipe

I am trying to simulate 1D advection and convection of a solute in the following blood vessel segment. I would like to know if this system can be simulated in COMSOL or MATLAB. I have used pdepe ...
0
votes
0answers
83 views

Why does the matlab command **chol(A)** slower than **chol(A,'lower')** for a large sparse SPD matrix?

For a SPD matrix A, there exists Cholesky factorization $A=LL^T$ or $A=R^TR$, where L, R are a lower and upper triangular matrix, respectively. Also in matlab, there has a command R = chol(A) which ...
0
votes
0answers
41 views

Solving Parabolic PDE using Matlab

I have the following pde (Burger's equation) for $\epsilon>0: u_t+u.u_x=\epsilon.u_{xx}$ and $x\in \mathbb{R},t>0$ and the initial condition: $u(x,0)=\phi(x)=1_{(-\infty,0)}(x)$. I want ...
0
votes
0answers
77 views

Reducing run time of a numerical calculation using a mex file in Matlab

I wrote a Matlab code that involves doing a numeric calculation (relaxation), but it is quite slow. I learned of the possibility of using a mex file to run a C code and integrate it into Matlab, so I ...
0
votes
0answers
210 views

How to do a Hoshen–Kopelman algorithm in Matlab with periodic boundary conditions?

Say I have an array s with elements of 0 and 1. From my understanding, a Hoshen–Kopelman algorithm for s will be (in 3 ...
0
votes
0answers
33 views

Fit exponential convergence

I'm working with a numerical algorithm whose output $y$ asymptotically approaches a certain unknown value $a$. I expect an exponential convergence, i.e. the data $y$ given by my algorithm should be ...
0
votes
0answers
26 views

Simulating Anderson model, have problem with momentum representation (MATLAB)

I want to change from real-space representation to momentum-space representation I have a Hamilton-operator (Anderson-model), and I calculated some kind of entropy of its eigenstates (this is working, ...
0
votes
0answers
61 views

Computing Trajectory Equations of Kerr Geodesics

I want to numerically solve the trajectory equations of a Kerr geodesic given by wikipedia in Matlab. The trajectories look like: I implemented the equations and solved it with the standard Runge-...
0
votes
0answers
386 views

Solving a non-convex optimization problem using fmincon

I am trying to solve a non-convex optimization problem using fmincon(). At each iteration, I am iteratively looking for the optimum value and when the termination ...
0
votes
0answers
247 views

How to form the stiffness matrix for the Poisson equation using a spectral method

This is a follow-up question to How do I form the Chebyshev differentiation matrix in MATLAB? The goal of the following code is to solve the Poisson problem: ...
0
votes
0answers
320 views

3D Diffusion Equation in Fourier space

I'm solving the 3D Diffusion equation $$u_t=k(u_{xx}+u_{yy}+u_{zz})$$ in MATLAB using Fourier techniques. I assume a 3D Fourier expansion $(e^{-ipx},e^{-imy},e^{-imz})$of the solution. Physical ...
0
votes
0answers
140 views

1D fit on a surface in matlab

I have a problem fitting a $N\times N$ ($32\times 32$ in this case) matrix in Matlab. Here is the deal I have this image, and I want to create 1 dimensional fit between the points and then be able ...
0
votes
0answers
76 views

Nonlinear 2D modeling of Neural Electromagnetic field in Matlab

I am trying to replicate the MATLAB simulation presented in this paper. More specifically, I have to code the solution to this equation $$\frac{a}{2R_i}\frac{\partial^2 V_m}{\partial x^2} - \left[g_\...
0
votes
0answers
106 views

Integration in MATLAB: Complicated integrand

Can I solve the integral given below using Matlab? $$\frac{C(J)}{C_0} = \frac{2e^J}{\pi}\int\limits_{0}^{\infty} \frac{e^{\frac{\gamma}{2}\left[1 - \sqrt{\rho}\cos(\theta/2)\right]}}{a_1^2 + a_2^2} [...
0
votes
0answers
82 views

Solving condensate density problem in MATLAB

I want to solve for $n_{0}$ for a fixed value of $n$, lets say $n=1$ $$ n= n_{0}+ \dfrac{1}{2}\int_{-1/2}^{1/2}dq\left(\dfrac{e_{q}+Un_{0}}{\hbar\omega}-1\right) $$ where $e_{q}=2[1-cos(2\pi q)] $ ...
0
votes
0answers
412 views

how to pick a submatrix of a sparse matrix quickly(matlab)

I have a large sparse matrix A and i want to pick the submatrix of it to do block jacobi iterations. For the blocks, i have get a matrix Q that contains the index of nonzero entries in its Jth column ...
0
votes
0answers
198 views

Histogram separation energy equation based on Bhattacharyya

I am working in level set method, specially Lankton method paper. I try to implement Histogram Separation (HS) Energy problem (Part III.C). It based on Bhattacharyya to control the evolution of ...
0
votes
0answers
2k views

Finite differences and Neumann boundary conditions

I am dealing with a highly nonlinear system of two PDEs. I already have a code to solve the system in case of Dirichlet boundary conditions. The explicit system is: $$ \begin{eqnarray*} \partial_{t}u ...
0
votes
0answers
196 views

Givens method for sparse matrix

I have a (very) large sparse matrix in CSC form and I'm supposed to factorize it. I've read that between Givens and Householder transformations, Givens is better for a sparse matrix. The problem is ...
0
votes
1answer
2k views

Faster code for double integration using Gauss-Legendre quadrature

I came with a the following code to evaluate a double integral using Gauss Legendre quadrature in MatLab ...