Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

Filter by
Sorted by
Tagged with
1 vote
1 answer
10 views

Numerical solution of 2D wave equation using Fourier transform and finite differences

This is the $2$-dimensional wave equation $$ u_{tt} = u_{xx} + u_{yy} $$ with initial condition $u(x,y,0)=f(x,y)$ and $u_{t}(x,y,0) = 0$. The inverse Fourier transform used is $$ u(x,y,t) = \iint \hat{...
user avatar
  • 111
0 votes
0 answers
19 views

Can't figure out how to continue coding this really long kind of recursive function in MATLAB

I'm trying to code the following recursive function which is a solution to a specific delayed differential equation: $$F(t)= F(nT + t') = e^{\int\limits_{nT}^{nT+t'} a(s)ds}\bigg( F(nT) - \int\limits_{...
user avatar
-2 votes
0 answers
59 views

Using Implicit Euler Method with Newton-Raphson method

So I'm following this algorithm and here is my attempt: ...
user avatar
  • 1
-1 votes
0 answers
57 views

Solving Burger's equation using second-order central upwind

I am numerically solving a Burger's equation with second order semi-discrete central upwind $$u_t+\left(\frac{u^2}{2}\right)_x=0$$ with the initial condition $$u(x,0)=\frac{1}{4}+\frac{1}{2}\sin(\pi x)...
user avatar
-2 votes
0 answers
52 views

ADI method for a 2D advection-diffusion equation

I have discretized energy equation (2D advection-diffusion equation) with ADI (Alternating Direction Implicit) method, like: $$\frac{\partial\theta}{\partial t}=\frac{\partial^2\theta}{\partial x^2}+\...
user avatar
3 votes
0 answers
126 views

Numerically solving a 6th order non-linear differential equation in Matlab

I've posted yesterday a question about solving a non linear equation : it was not clear so I am reformulating my question. I am trying to solve a high-order non linear differential equation presented ...
user avatar
  • 33
0 votes
0 answers
20 views

How to write a dynamic SDP using CVX?

Consider the following SDP $$ \begin{aligned} \min\quad&\text{tr}(CX)\\ \text{s.t.}\quad&\text{tr}(A_iX)=b_i,\quad i=1,\cdots,p\\ &X\succeq0 \end{aligned} $$ where $C$ and $A_i$ are given ...
user avatar
-1 votes
1 answer
52 views

The local and average Nusselt number in a square cavity

I am in the process of programming the local & average Nusselt number in a left vertical wall but my Matlab script gives me inappropriate values and it doesn't change with changing of Rayleigh ...
user avatar
3 votes
0 answers
61 views

Generalized Eigenvalue Problem using MATLAB

I'm trying to solve a generalized eigenvalue problem. I have two matrices $H$ and $S$ such that: $$ HX=λSX $$ I need to find the eigenvalues $\lambda$. The matrices $H$ and $S$ are real, asymmetric, ...
user avatar
1 vote
1 answer
110 views

What does the Chebyshev differentiation matrix look like for third and fourth derivative?

I have a PDE that contains both the 3rd derivative and 4th derivative. Example shown below $$ \frac{\partial u}{\partial t} =\frac{\partial}{\partial x}(u^3\frac{\partial^3u}{\partial x^3}) $$ $$ \...
user avatar
2 votes
1 answer
94 views

Numerical diagonalization of Hamiltonian

Framework I am trying to diagonalize the Bogoliubov-de Gennes Hamiltonian. The problem is that the Hamiltonian contains a Laplacian. This could be solved by using a discretized Laplacian. How I tried ...
user avatar
  • 21
0 votes
1 answer
76 views

Assembly of the Isoparametric Quadratic load vector in Matlab [duplicate]

I work to solve PDE using FEM in the case P2 on Matlab. I try to correctly assemble load vector using quadratic Lagrange shape functions $$b_i =(f,\phi_i)=\sum_{q=1}^{nq}f(r_q,s_q)*\phi_{i}(r_q,s_q)*...
user avatar
4 votes
1 answer
167 views

How can I solve a pde with second derivative boundary condition?

I have an equation like $$ \frac{\partial u}{\partial t} =A\frac{\partial^4u}{\partial x^4} $$ with boundary condition $$ u(x = \pm L,t) = 9; u_{xx} (x=\pm L,t) = 4 $$ I tried to use the method of ...
user avatar
0 votes
0 answers
32 views

Calculating Lyapunov exponent (LE) for pendulum using ellipsoid growth - code yields negative LEs

I was redirected here from physics stack exchange where hopefully my question is more appropriate. Per my advisor, I have read the textbook Chaos, an introduction to dynamical systems by Alligood, ...
user avatar
  • 11
2 votes
1 answer
143 views

Why is my Runge-Kutta 4 solution to the 1-D advection equation decaying so quickly?

I am trying to numerically solve the advection equation $y_t + y_x = 0$ using a the "classical" Runge-Kutta 4 explicit timestepping method, along with a left-hand finite difference ...
user avatar
  • 23
1 vote
0 answers
86 views

How to discretize PDEs using Chebyshev spectral method into a system of differential algebraic equations (DAEs)?

Let's take the heat equation. We have a time derivative and spatial derivative. How to discretize the spatial derivative using Chebyshev spectral method and convert it into DAEs? Like in the form of $ ...
user avatar
0 votes
1 answer
43 views

Numerical Error source when dealing with integer series

I am currently trying to compute the value of the first Fibonacci number recursively. the idea is as follow: Compute $f_{n}$ and $f_{n-1}$ for $n = 2,...,100$, Compute $f_k$ for $k = n−2, n−3, \dots, ...
user avatar
  • 103
2 votes
0 answers
56 views

Cyipopt fails to converge for NLP problem which fmincon() can solve

I'm currently trying to implement a python script for solving a constrained nonlinear optimization problem with ~800 variables and 2 constraints, one linear and one nonlinear. There already exists a ...
user avatar
0 votes
1 answer
66 views

How to remove singularit​ies/discon​tinuities on 3D plots in Matlab?

I want to plot some functions f(x,y) including singularities. For example; f(x,y)=tan(x-y) In Matlab, when I run the following code ...
user avatar
  • 101
0 votes
1 answer
129 views

Solving ODE with Spectral Method using Chebyshev Polynomials

I would like to solve following the basic equation of linear elasticity (for simplicity in 1D) $$ \frac{d}{dx} \left( E \frac{du}{dx} \right) = 0 \quad \textrm{with} \quad u(1)=0, \; u(-1)=b $$ ...
user avatar
0 votes
1 answer
49 views

why is $Hx= x-2u^{H}xu$ ? why not $Hx= x(x-uu^H) + 2((u^Hx)u)^2? $

I have some confusion in this diagram My confusion : why is $Hx= x-2u^{H}xu$ ? why not $Hx=x(x-uu^H) + 2((u^Hx)u)^2? $ My thinking is that by using pythogoras theorem blue line(vector) denotes ...
user avatar
  • 101
2 votes
1 answer
83 views

High precision numerical integration of discrete data with Matlab

I have discrete data of a function plotted below: The "Y" values of the function near "X=1.57" are very close to each other and zero, like 9.25558265263186E-11 and 5....
user avatar
  • 23
0 votes
0 answers
31 views

Solving a time-independent 2D Schrödinger equation using PDE Toolbox in MATLAB

I want to solve the following PDE eigenvalue problem, $$-\left(\frac{\partial^2}{\partial x^2}+\frac{\partial^2}{\partial y^2}\right)\psi_n(x,y)+x^2y^2\psi_n(x,y)=E_n\psi_n(x,y)$$ inside a square with ...
user avatar
  • 129
10 votes
2 answers
856 views

Why is RK45 used as the "default" method for non-stiff ODEs rather than a multistep one?

From what I read, the "default" go-to method for non-stiff ODEs is the Dormand-Prince Runge-Kutta pair; for instance, in Matlab docs, "Most of the time, ...
user avatar
2 votes
2 answers
70 views

Possible to use Iterative FD methods to solve a transformed non square domain [matlab]?

For the 2-D Poisson equation $$-(u_{xx}+u_{yy}) = f \ \ \text{where} f = 1$$ For boundary conditions $$\frac{\partial u}{\partial n} = 0 \ \text{on AB and AD}$$ $$ u = 0 \ \ \ \text{on BC and CD no-...
user avatar
  • 23
0 votes
0 answers
72 views

Solving an apparently tricky geodesic BVP in Matlab

I want to be able to solve the BVP $$\ddot \mu_k = -\frac{\mu_k}{2} \left ( \sum_{i=1}^n \frac{\dot \mu_i^2}{\mu_i} - \frac{\dot \mu_k^2}{\mu_k^2} + \frac{ \left [ \sum_{i=1}^n \dot \mu_i \right ]^2}{\...
user avatar
0 votes
1 answer
68 views

Time & Space matlab discretization Finite Differences confusion

I have been trying to solve this equation and write the finite difference scheme in matlab for months, but I still am not successful. Given the KdV Equation $$\tag{1}u_{t} -6uu_x+u_{xxx}=0$$ I have ...
user avatar
  • 23
1 vote
0 answers
115 views

Numerical evaluation of Duhamel's integration

I am trying to numerically evaluate the following Duhamel's integration: $$ x = \frac{-1}{\omega_d} \int_0^t \ddot{x}_g (\tau) e^{-\zeta \omega_n(t - \tau)} \sin{\left( \omega_d (t - \tau) \right)} d\...
user avatar
2 votes
1 answer
115 views

Mineral dissolution and solute transport around a solid

I am trying to simulate solute transport of acid (HCl) and consequent mineral dissolution around a grain (calcite). The governing equation for transport is the advection-diffusion equation, given as: ...
user avatar
  • 47
0 votes
0 answers
58 views

Solve simultaneous differential equations with embedded functions and a parameter estimation

The aim is to solve the below equations and plot $m$ with time, i.e. $\frac{dm}{dt}$ $k$ is unknown and needs to be estimated. For the parameter estimation, the below values in the table for m versus ...
user avatar
2 votes
0 answers
72 views

Solute transport around a solid obstacle

I am a newbie in CFD and single/multiphase flow and transport in general. As part of my quest to learn, I am trying to model solute transport around a solid object in the center of a 2D domain. The ...
user avatar
  • 47
3 votes
2 answers
186 views

Is there a Python version of the ODE tool pplane?

This is the same question as this one, except for Python instead of Mathematica. Basically, the MATLAB software PPLANE is a staple in ODE courses. Is there a Python equivalent? I don't know much about ...
user avatar
4 votes
2 answers
130 views

Backward Euler + Quasi Newton(Broyden) method fails to solve Van der Pol's equation(Stiff ODE)

The first guess is using the forward Euler approach. The first jacobian is using finite differences. Then NR method is used to solve for the next iteration and Broyden's method is used to update the ...
user avatar
3 votes
1 answer
87 views

Find $x$ that satisfy $(I-A^*A)+x(\frac{A+A^*}{2})\prec0$ using LMI or SDP on Matlab

Given $A\in\mathbb{C}^{n\times n}$, I want to use LMI or SDP to find feasibility of $x>0$ in the following inequality: $$(I-A^*A)+x(\frac{A+A^*}{2})\prec0,$$ where $D\prec0$ means that $D$ is ...
user avatar
  • 183
3 votes
1 answer
87 views

Type of computer used for computation

In some scientific papers I see that authors provide what type of simulation tool and what type of computer was used for computation. For example: The computations were performed using MATLAB in ...
user avatar
  • 183
1 vote
0 answers
19 views

How can this attempt to implement a Milstein numerical approximation for an Ito process of multiple components be fixed?

I have been reading Kloeden and Platen's Numerical Solution of Stochastic Differential Equations, and have more or less been trying to systematically complete the various exercises therein as I go ...
user avatar
0 votes
1 answer
67 views

Best search algorithm for optimal weight factor in SOR method

I had written an algorithm that searches for the optimal weight parameter to be implemented in the successive-over relaxation (SOR) method which worked cleanly by vectorizing the interval and for ...
user avatar
  • 155
1 vote
1 answer
139 views

2-norm and infinty norm of a system in controls

How to compute 2-norm or infinity norm of following system? i am confused whether to calculate using simple matrix theory "where it don't regard for s domain" or H2 and H-infinty norm. ...
user avatar
1 vote
1 answer
1k views

What is difference between L2 norm and H2 Norm?

When someone refers 2-norm of system,L2 and H2 are used interchangeably by author and is rather confusing. Even the matlab has different functions for H-infinity norm and L-infinity norm. as shown in ...
user avatar
-1 votes
1 answer
41 views

relres in gmres MATLAB

I think the relres in MATLABis the form that relres = norm(M(b-Ax))/norm(M\b),when it smaller than tol then stop the iteration. I want to know how to change relres to norm((b-Ax))/norm(b). Or use ...
user avatar
  • 1
1 vote
2 answers
181 views

Continuation of solution to $-\nabla\cdot (k(x,y)\nabla u)=f$

I'm trying to solve the following problem, I had previously opened another discussion for the implementation and well, it seems that it has turned out well, it can be found here. I need to calculate ...
user avatar
  • 123
1 vote
0 answers
48 views

Can we solve can overdetermined coupled equations in matlab?

...
user avatar
  • 111
2 votes
1 answer
103 views

Vectorization Matlab/Octave of Markov Matrix Powers

I have just created a code snippet in Octave/Matlab that aims to create a plot which shows the accuracy of an initial probability vector $\vec{\pi}$ derived from the transition probability matrix $\...
user avatar
3 votes
1 answer
180 views

How can I extract the banded or block diagonal part of a sparse matrix in MATLAB?

Given a large sparse (square) matrix in MATLAB, how can I extract the banded or the block-diagonal parts (of fixed size) of it efficiently? These are useful operations when prototyping and testing ...
user avatar
0 votes
1 answer
57 views

Efficient solution to linear system involving Kronecker sum in MATLAB

High dimensional finite difference problems often lead to linear systems of the form $$ A x = b, \qquad A = B_1 \oplus B_2 \oplus \cdots \oplus B_d, $$ where $\oplus$ denotes the Kronecker sum. $B_i \...
user avatar
1 vote
1 answer
430 views

What is the use of arrayfun if a for loop is faster?

This may not be so much of a scientific computing question but more of a MATLAB question, if that is the case, please feel free to close or migrate the question. Root-finding problems are commonly ...
user avatar
0 votes
2 answers
372 views

Implementing routine for $-\nabla\cdot (k(x,y) \nabla u)=f$ in Matlab

I am solving the Poisson Equation for 2D given by the following expression: $$-\nabla\cdot (k(x,y) \nabla u)=f$$ in a rectangle with Dirichlet conditions on the boundary using Matlab. In principle I ...
user avatar
  • 123
0 votes
0 answers
149 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 ...
user avatar
5 votes
2 answers
590 views

Specifying ode solver options to speed up compute time

I'm specifying the 'JPattern', sparsity_pattern in the ode options to speed up the compute time of my actual system. I am sharing a sample code below to show how I ...
user avatar
  • 581
4 votes
1 answer
112 views

How are Matrices Stored in MATLAB?

I have this simple question but I am trying to figure out why: Are matrices stored column-wise in MATLAB? If so then why? I theorize that they are stored column-wise because the memory does not have ...
user avatar
  • 155

1
2 3 4 5
16