Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

Filter by
Sorted by
Tagged with
0
votes
1answer
84 views

MATLAB: Matrix whose elements depend on its indicies

I am trying to put the function $$ f(\mu,\nu) = i^{\nu-\mu} \sum_{0}^{19} H_{\mu-\nu}(7j) + \delta_{\mu,\nu}\ ,$$ $\mu, \nu =-3,-2,...2,3$ into a 7x7 matrix, where $H$ is the Hankel function of the ...
2
votes
1answer
2k views

3D Solid 8 Node FEM Matlab Code

So this semester, I'm taking a Finite Element Method course at my graduate school. We started out making codes for 1D bars and came all the way to 8 node solid elements. However, I seem to have run ...
-1
votes
1answer
200 views

ODE15s: unable to meet integration tolerances

I have to solve $$\left\{\begin{matrix} \ddot{R}=-\frac{3}{2}\frac{\dot{R}^{2}}{R}+\frac{1}{R\rho}\left [P_{v}(T_{\infty})-P_{0}-a_{1}t^{2}-a_{2}t+\frac{(L\rho_{g})^{2}}{hT_{\infty}}\dot{R}-4\mu \frac{...
1
vote
0answers
226 views

MATLAB ODE15s: imaginary parts

I have to solve $$\left\{\begin{matrix} \ddot{R}=-\frac{3}{2}\frac{\dot{R}^{2}}{R}+\frac{1}{R\rho}\left [P_{v}(T_{\infty})-P_{0}+\frac{(L\rho_{g})^{2}}{hT_{\infty}}\dot{R}-4\mu \frac{\dot{R}}{R}-\frac{...
2
votes
1answer
394 views

Contour plot of a scalar function over the complex domain in MATLAB

I'm trying to make a 2D contour plot of a function with a complex input and a real output, namely: $f(z=x+iy)= |z^2-3z|$, on MATLAB. I want to make a contour plot of f, such that the axes are $(x,y)$, ...
2
votes
1answer
122 views

Numerically Approximate $[n\cdot\nabla u_h],$ without using Matlab function

Suppose that $\Omega\subset\mathbb{R}^2$ and we define the triangulation $\mathcal{T}_h$ where, $$\mathcal{T}_h=\bigcup_{i=1}^nK_i$$, with $K_i$ are triangles. We have the explicit a posteriori ...
0
votes
3answers
1k views

Matrix of linear transformation in MATLAB

How can I determine a matrix $R$ in matlab such that, given a known matrix of coefficients $A$ gives me back its row reduced echelon form? Obviously I need an algorithm/function that works also with ...
0
votes
2answers
463 views

Matlab: ode45 loop

I have to solve this equation $$\ddot{x}x = -\frac{3}{2}\dot{x}^2 + \frac{\dot{x}}{h} + \sin(t)$$ where $h$ is defined by $$h = \left(\frac{\dot{x}}{h}\right)^{1/3} + \frac{\dot{x}}{h}$$ My idea ...
0
votes
2answers
214 views

Integrate result of finite element calculation in MATLAB

I have a PDE that I solve in MATLAB over a 2D domain using the "recommended workflow", i.e. the functions descg, ...
-1
votes
1answer
386 views

Which ODE solver in Matlab allows me to advance in just one timestep only

[t,y] = odeXX(odefun,tspan,y0) I have a solver odeXX, and the tspan = [0 0.0001]. It seems that for any ode solver in MATLAB, they integrate by breaking ...
0
votes
1answer
164 views

Optimization with Yalmip [closed]

I would like to solve in Matlab the following optimization problem $$\begin{array}{ll} \text{maximize} & \bigg\| \displaystyle\sum_{l=1}^{2}\alpha_l \int_{\tau_{m+l-1}}^{\alpha_1\tau_m+\alpha_2\...
1
vote
2answers
447 views

Solving PDE in 1D with FD and MATLAB

I have to solve the following equation: $-u_{xx}=1$, with $x\in(0,1)$ and $u(0)=0,u(1)=0$. I have to solve it with the following numerical scheme: $\frac{1}{h_k^2}(-\frac{1}{2}u_{k-1}+u_k-\frac{1}{...
5
votes
3answers
2k views

Efficiently computing the product of a multi-dimensional matrix (or tensor) and vectors

Update: Thank you very much for all of you who answered below. I'm studying each answer now. In the long term, I'm more interested in solutions that work for sparse tensors (sorry I should have ...
1
vote
1answer
7k views

Implementation of the Jacobi iteration to find the solution to $Ax = b$

I implemented the Jacobi iteration using Matlab based on this paper, and the code is as follows: ...
1
vote
0answers
44 views

Solving HJ using Hopf-Lax formula (Burgers case)

Hi I want to approximate $u(x,t)$ solution of: $\begin{cases}u_t+H(u_x)=0 \\u(x,0)=u_0(x)= e^{−(x−3)^2} \end{cases}$, where $H(u_x)=\frac{u_x^2}{2}$ and my spatial domain is $\Omega=[0;10]$. Now i ...
1
vote
2answers
684 views

Find a permutation matrix (using the Matlab's function $symrcm$) of a matrix $A(2:end, 2:end)$

I've the following Matlab code: r = symrcm(A(2:end, 2:end)); prcm = [1 r + 1]; spy(A(prcm, prcm)); where A should be sparse ...
1
vote
1answer
457 views

Pool two computers for MATLAB parfor without MDCS

I have two identical computers, both with 4 dual cores and MATLAB installed on them. They are connected to the same network. Is there anyway I can run a parforloop using the computation power of both ...
2
votes
2answers
591 views

PageRank using Inverse Iteration Method by Cleve Moler

I was trying to understand how to use the inverse interation method to compute the page rank as an exercise. In this chapter (page 4) about page rank (by Cleve Moler), the author suggests to use the ...
0
votes
1answer
70 views

Difference Equation PDE in MatLab

I would like to program the following difference equation. Find numbers $v_{i,j}$ so that for $1\leq i\leq 4$, $0\leq j\leq 5$: $$ v_{i,j+1} = (0.1)v_{i+1,j} + (0.8)v_{i,j} + (0.1)v_{i-1,j} $$ In ...
-2
votes
1answer
255 views

Solving a differential equation using numerical methods and matlab

(a) Consider the following differential Equation $$Y'(t)=\frac{1}{1+t^{2}}-2[Y(t)]^2$$ $$Y(0)=0$$ The exact solution is $$Y(t)=\frac{t}{1+t^2}$$ Using the Euler method to solve the following ...
9
votes
1answer
632 views

Matrix Balancing Algorithm

I have been writing a control system toolbox from scratch and purely in Python3 (shameless plug : harold ). From my past research, I have always complaints about ...
0
votes
1answer
107 views

Solving ODEs of Switched Systems using MATLAB ODE suite

I have the following code to execute: $X$ = [0;0;0;0]; $sw$ = 0; ...
1
vote
0answers
1k views

Nelder-Mead algorithm with constraints

Im currently implementing a Nelder-Mead algorithm in MATLAB that can deal with constraints. In detail, the constraints should be added to the objective function with a Lagrange Multiplier($\lambda$) ...
1
vote
2answers
342 views

Defining a pixel neighborhood in an array in MATLAB

I am working with matrix operations in MATLAB, and I would have the following problem. I have matrix containing zero elements: a=zeros(100,100) and another ...
1
vote
1answer
218 views

fast adaptive quadrature on equispaced 2-D grid

I need to numerically evaluate 2-D integrals of the form: $$ \mathcal{I}(\theta) = \int_{0}^{1} \int_0^1 \varphi_\theta(x,y) dx dy $$ where $\varphi_\theta$ is a family of smooth functions indexed by ...
1
vote
1answer
86 views

Name of third-party Matlab packages for solving PDEs

I am interested in working with systems of PDEs in two spatial dimensions, as part of a mathematical modeling project. The systems of PDEs are coupled, and there is no convenient reduction to 1 ...
0
votes
1answer
1k views

Use Monte Carlo method to simulate consecutive decay in MATLAB

I'm trying to use MATLAB to simulate an atom decay process by using Monte Carlo approach. The process is as follow: Suppose that atom 1 decay to atom 2, which, in turn, decay to stable atoms of type ...
1
vote
0answers
100 views

Adjoint of the MATLAB $\tt dwt3$ (3D wavelet transform) operator

How do I compute the adjoint of MATLAB's dwt3 operator? In other words, how do I compute the adjoint of the linear operator that takes a 3D complex array ...
1
vote
1answer
106 views

Numerical Integration [duplicate]

Let $\alpha=1.714$ and $\lambda=-v(1-v^{\alpha})/\alpha$, where $0<v<1$. Consider $\phi(v)=\exp\{\int_{v_{0}}^{v}\frac{1}{\lambda(t)} dt \}$, where $0< v_{0} <1$ is an arbitrary chosen ...
1
vote
2answers
160 views

Data cloning into 3D matrix

I am working with MATLAB, and I would have the following problem. I have the following matrix of random numbers rand(200,200) and I need to create a 3D matrix ...
0
votes
1answer
220 views

flux limiter problem

I have worked with MATLAB for calculating below equation for any time ($n$) and place($i$). In this equation, flux limiter is used. $$C(i,n+1)=C(i,n)-V\left[1+\frac{1}{2}\psi(r_i)-\frac{1}{2}\frac{1}{...
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 ...
0
votes
0answers
248 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: ...
1
vote
2answers
416 views

Generating 4D Plots in Matlab

I have some data in the form of: ...
1
vote
0answers
70 views

Gauss Seidel moving mesh AMR hamilton Jacobi

I was trying to implement a moving mesh algorithm using Gauss Seidel, so: I have a pde like this (Hamilton - Jacobi eq) $\begin{cases}\phi_t+H(\phi_x)=0 & [-1,1]\times [0,T]\\\phi(x,0)=\phi_0 &...
3
votes
1answer
2k views

How do I form the Chebyshev differentiation matrix in MATLAB?

I have some code that does exactly this, but I do not like to use things I do not understand. Here is the code ...
1
vote
1answer
494 views

How does Matlab `surf` perform interpolation?

When I use Matlab's surf function, I notice that I can't re-perform its interpolation, which produces unreliable results. Do you know what does ...
1
vote
2answers
535 views

Can I model laminar incompressible fluid flow and heat transfer in MATLAB's PDE toolbox?

I have a system of PDEs in cylindrical coordinates that needs to be solved: 1. Continuity equation 2. Incompressible Navier stokes ( in r & z coordinates) 3. Heat transfer equation with both ...
1
vote
1answer
326 views

Matlab: Creating a matrix that represents a colored, sinusoidally-modulated grating

I would like to draw a texture (in Matlab - Psychtoolbox) which is composed of a sinusoidally-modulated isoluminant (magenta & cyan) grating. I do have the RGB matrices of the two phases (for ...
0
votes
2answers
325 views

What is wrong with my code for solving Poisson equation with one side Neumann boundary condition?

I wrote a Matlab code for solving 2D Poisson equation $u_{xx} + u_{yy} + f(x,y) = 0$ on $[a,b]\times [c,d]$ with neumann boundary condition on $x = b$ and the other boundary conditions are dirichlet,...
0
votes
1answer
2k views

Solving Time dependent Schrodinger equation using MATLAB ode45 [closed]

The Schrodinger equation for time-dependent Hamiltonian is $$i\hbar\frac{d}{dt}\psi(t) = H(t)\psi(t) \, .$$ I try to implement solve the Schrodinger equation for time-dependent Hamiltonian in ODE ...
2
votes
1answer
807 views

Defining Cauchy principal value in MATLAB (or Scilab/Maple)?

How to define a variable which is an integral involving cauchy principal value inside in any computer programming language? I want to know how to break down the procedure step by step from a ...
2
votes
1answer
156 views

Approximating improper integral with FFT

In d'Halluin et al. (2005) (http://imajna.oxfordjournals.org/content/25/1/87.short) the authors claim that the correlation integral $$ I(x) = \int_{-\infty}^{\infty} V(x+y) f(y) dy $$ can be ...
3
votes
1answer
335 views

Computational time not proportional to integration interval in ODE-solver?

I am running octave and i have been trying ode45, ode54, ode23 etc to integrate the equation ` $$Q''(t) = B\cos(Q)\sin(\omega t)$$ $$Q(t=0)=0.$$ When the time interval to be integrated increases, the ...
1
vote
0answers
130 views

Conservative Short Sales Portfolio Optimization with MatLab code help

I'm trying to solve the optimization problem below with MatLab, but I'm unsure of how to modify the constraints in the quadprog function (or how to add the constraints with the Portfolio object). In ...
0
votes
1answer
1k views

Conjugate symmetry in MATLAB?

I have a large vector with complex numbers. How do I check whether it a conjugate symmetry vector? If not, is there any way to transform it?
0
votes
1answer
106 views

Discretized matrix from the integral kernel function

Recently, I read a paper [1] and then I want to handle the two-dimensional linear integro-differential equation \begin{equation*} -\triangle u + q\Big(\frac{\partial u}{\partial x} + \frac{\partial u}{...
1
vote
0answers
117 views

Stiffness emerges as number of ODEs increases

I want to solve a system of ordinary differential equations with Matlab. I need this to solve a mechanical engineering related problem. If $n$ is the number of degrees of freedom of my mechanical ...
0
votes
1answer
249 views

Nice plot of f(x)

A user has this nice graph of f(x) on his profile and I want to learn how to do it in matlab or Gnu octave. ...
2
votes
1answer
176 views

Difference between Brent's and Alefeld-Potra-Shi for root finding

I need to find the (unique) root of a nonlinear function $f(x)$, $x \in \mathbb{R}$. For the record, $f(x)$ is the CDF of a probability density minus a constant $0 < p < 1$ (I am inverting the ...

1
5 6
7
8 9
16