Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

1
vote
1answer
67 views

Solving for $C$ in $Q = YCZ$ using least squares in Matlab

I am trying to solve for the matrix $C$ in $Q = YCZ$ in matlab. I have preliminary results but they don't seem realistic. Here, $Q$ is $n \times m-1$, $Y$ is $n \times p$, $C$ is $p \times m$ and $Z$ ...
0
votes
1answer
133 views

Derivatives of a Chebychev polynomial

I am using Chebychev collocation nodes for approximation, and my problem requires me to calculate derivatives of the polynomial. I have been reading from a few sources, but I am not sure I understand ...
-2
votes
1answer
188 views

Adding Non-Linear source term to 2d Implicit MATLAB code

I'm running out of time for this code so any help would be greatly appreciated. I am currently coding the 2D heat/diffusion equation in matlab but i'm having trouble adding in the source term. my ...
0
votes
1answer
219 views

Modelica and SIMULINK yield completely different results

I'm trying to simulate a 1D model of two bodies sliding on each other with a Coulomb friction in between. As I have explained here I modeled the friction as : The force required to keep two bodies ...
0
votes
1answer
286 views

Is the exponential function, e^x, very expensive to compute in Matlab and harmful to my computer?

Is the exponential function problematic and very expensive to compute in Matlab? When I write a new term for my model of ODEs that has an exponential term in it, the program almost never finishes ...
7
votes
4answers
190 views

In Matlab, how can I be consistent with units?

I am modeling some aerodynamics equations and am using meters / centimeters, kilograms, and seconds. I've heard that, "matlab doesn't know units". So, how can I make sure that it does? Just ...
3
votes
2answers
222 views

Writing a programming code directly from the mathematical formula?

For using any programming language, a mathematical formula should be written in the corresponding code. I wonder if there is any service (for any programming language, Matlab, Mathematica, Python, etc)...
3
votes
1answer
191 views

How to compute the Frobenius norm of matrices whose entries are either too large or too small?

While implementing in Matlab the Frobenius norm of a matrix $$\| A\|_{\text F} := \sqrt{ \sum_{i=1}^m \sum_{j=1}^n a_{ij}^2 },$$ a problem arises when numbers are too big or too small: If a number ...
3
votes
1answer
339 views

Numerical propagation of a density matrix using Liouville von Neumann equation

I want to look at time evolution of the density matrices of some, very simple, spin systems, but I am having trouble with my approach. I want to use a simple for-...
0
votes
1answer
38 views

Plotting using 'colorbar' in MATLAB [closed]

I am trying to plot a figure similar to the one attached here,I tried searching how to do a similar kinds of plot and i found about 'colormap','colorbar' in MATLAB. Actually I want to plot this ...
1
vote
1answer
182 views

Create mesh for complicated 3D object for finite element analysis

I see images of steel connections, concrete dams, and other complicated 3D objects in papers which finite element analysis has been performed on them. My questions are: How these objects are created ...
0
votes
2answers
122 views

Computing Eigenvectors in MATLAB

I am assigned to compute eigenvalues and eigenvectors in MATLAB of a 2x2 matrix: $$ A = \left( \begin{matrix} 3 &0\\ 4 &5\\ \end{matrix} \right) $$ I know that the textbook's solution states ...
0
votes
1answer
61 views

Non linear programming solvers with API for MATLAB?

I'm facing a non-linear programming problem which currently I'm solving with fmincon function of MATLAB. However, I'm not very happy with computation times and solution convergence since it only ...
1
vote
1answer
256 views

Kronecker product among multiple arrays

I was wondering whether there is a smart and efficient way in Matlab to compute the kronecker product of several 1D arrays. What I mean is something like this ...
0
votes
1answer
87 views

finding the growth rate from numerical data

Suppose i have a bunch of 10 data points and i have to conclude whether the increase is $n^2,n^3,\cdots,2^n,3^n, e^n,\cdots$. For example i have the image:- Now the increase is either polynomial or ...
3
votes
2answers
345 views

Complex Eigenvalues using eig (Matlab)

I wanted to find and plot the eigenvalues of large matrices (around1000x1000). But discovered when using the eig function in matlab, it gives complex eigenvalues when it shouldn't. For example, in the ...
3
votes
0answers
80 views

Precision not improving by decreasing step-size in nonlinear Schrödinger

I tried to simulate soliton propagation by solving the nonlinear Schrödinger equation using the split-step Fourier method. The following is an example of the Matlab code copied from a textbook. ...
1
vote
0answers
41 views

Discrepancy in estimating boundary stencil for finite difference method

I am trying to estimate the FD stencil for boundary as mentioned in this paper (section 4.1) using MATLAB. The stencil order (6th) is higher than the one mentioned in paper (4th). $$ f_1' +\alpha f_2'...
0
votes
2answers
199 views

Matlab, Mathematica & LAPACK returning 3 different eigenvectors

(I'm not sure which of math.se / stackoverflow / scicomp.se is the right place to ask this question) I have a C++ code which generates a complex matrix and then calculates its eigenvalues and ...
0
votes
1answer
106 views

B-Splines Matlab Package

I'm looking for a good Matlab package/library for B-Splines approximation. Ideally, it would take knots $t_1, \ldots , t_n$, and data points $g(t_1),\ldots , g(t_n)$, and Produce $$Vg :\,= \sum\...
1
vote
0answers
217 views

Vectorizing Matrix Multiplication

I would like to do the following operation: I have a "4D" matrix A and a "3D" matrix B. Both A and B are actually 2D matrices, where for A, each element is a 2D matrix, and for B, each element is a 1D ...
1
vote
0answers
28 views

Pseudo-Spectral cosine transform

I'm trying to solve the following equation $$u_t = u_{xx} + u(1-u^2), u_x(\pm 1) = 0,$$ using the Fourier cosine transform. The nonlinear term gives a convolution which I would rather avoid, which is ...
1
vote
0answers
104 views

Second Quantization in Matlab

This question may be more suited for physics.stackexchange, but I saw this post was recommended for StackOverflow or Computational Science, so I'm asking my question here. I am trying to write a ...
1
vote
0answers
66 views

Approximating derivative of numerical solution (using ode45) within event function

The issue I have is having to compute the derivative (in real time) of the solution produced by ode45 within the events function. Some pseudo-code to explain what I'm mean is, ...
0
votes
0answers
28 views

Comparison of different methods for solving $\partial_tA=\nabla^2_xA$ [duplicate]

For testing I would like to solve the equation $$ \partial_tA=\nabla^2_xA,\,A_0=\sin(x) $$ In order to solve it, I use an implicit solver $$\left(1-\frac{\nabla^2_x}{2}dt\right)A_{n+1} = \left(1+\frac{...
2
votes
1answer
351 views

Crank-Nicolson algorithm for coupled PDEs

Assumed I have the following two coupled equations $$\begin{split} \partial_tA&=a_0AB\\ \partial_tB&=b_0AB \end{split} $$ but I am not sure how to calculate them. One approach is a crank-...
1
vote
0answers
129 views

Why can I not solve the negative advection equation (backwards in time)?

Suppose we have the negative, inhomogeneous advection equation: $$\left(\frac{\partial}{\partial x}-\frac{1}{c}\frac{\partial}{\partial t}\right)v(t,x)=u(t,x)\qquad(t\in\mathbb{R}_{+},x\in\mathbb{R})$$...
0
votes
1answer
199 views

Interior penalty discontinuous Galerkin Matlab implementation

I want to solve the 2D poisson problem using the interior penalty discontinuous Galerkin methods: −∇a(x)(∇u)=0 in Ω. The variational formulation is such that : $$a_{\epsilon}(u,v)=\sum_{K\in T_h}\...
1
vote
0answers
130 views

Accuracy of finite difference method for heat equation on a disk

To study an approximation for the heat equation $$\frac{\partial^2 u}{\partial r^2}+\frac{1}{r}\frac{\partial u}{\partial r}+\frac{1}{r^2}\frac{\partial^2 u}{\partial\theta^2}=f(r,\theta)$$ on the ...
0
votes
0answers
140 views

Solving optimal control problems using third-party NLP solvers

I've been doing a bit of work on the so-called pseudospectral optimal control for trajectory optimization of a launch vehicle into orbit. However, comparing my results to the literature, I seem to be ...
1
vote
1answer
51 views

Calculating a limit as parameter goes to infinity

I have a fair background in pure mathematics and right now my project is a numerical implementation of a certain algorithm. I have some numerical background, but not all that much, so the question is ...
1
vote
0answers
308 views

How accurate is cumtrapz in MatLab?

Say I have a set of discrete acceleration data and want to integrate it to get a set of velocity data. How accurate is the cumtrapz (Cumulative trapezoidal ...
0
votes
1answer
882 views

Multiplying two functions in MATLAB

I want the product of two functions $f(x),g(x)$ $$f(x) = x + \sin(x)\\ g(x) = x - \sin(x)$$ then $$f(x)g(x) = x^2 - \sin^{2}(x)$$ How could I compute the product of two functions?. I tried ...
8
votes
0answers
394 views

Numerical implementation of the Dirichlet-to-Neumann map

I am solving the Dirichlet problem $$ \begin{cases} \Delta u = 0, \\ u|_{\partial D} = f, \end{cases} $$ in a $2d$ domain $D$ using the finite element method. What I want to get is the ...
0
votes
1answer
175 views

4D visualization in MATLAB

I have a function of 3 variables like $V= f(r1,p,r2)$, I want to plot these 4 data in one graph to be able to capture behavior of V with respect to all three variables. I searched a little bit and ...
1
vote
1answer
158 views

Solid volume calculation

In order to calculate the volume of the solid defined by $$\frac{51}{100} (\cos x \cos y+\cos x \cos z+\cos y \cos z)+\cos x+\cos y+\cos z+1\le0$$ where $x,y,z\in[0,2\pi]$ I used the following code ...
1
vote
3answers
296 views

2D simulation of a particle with different diffusion coefficient in different directions of the particle

How can one simulate diffusion of a particle which has a natural axis and diffusion coefficient of the particle in the direction of the axis is D_1 and in perpendicular to the axis is D_2? Could ...
0
votes
1answer
51 views

Matlab struct vector

(I resume my question with a simple example) I want to create a struct in matlab/octave as follows c(1).x = [0 1]; c(2).x = [0 1]; ... c(100).x = [0 1]; ...
1
vote
1answer
285 views

Plot 2D piecewise constant in matlab in a finite elements mesh

I need to generate a discontinuous plot (piecewise in each triangle) in matlab, something like: This plot is from http://www.alecjacobson.com/weblog/?p=3616, but I don't understand how generate it. ...
1
vote
0answers
74 views

Composite Laminate Mass Matrix Help

So, as the title of the post implies, I'm making an FEM code for a composite laminate plate using the Mindlin plate theory. And, as I am trying to get the mode shapes for the plate, I needed to make a ...
3
votes
1answer
423 views

Position Estimation using 2D multilateration for non-intersecting distances

I am trying to estimate the position of a point $P$ in Matlab. I have $n$ access points (AP) at known positions ($n>2$) as well as the distances to the point $P$ from each AP. These distances all ...
3
votes
1answer
1k views

How to compute the Helmholtz decomposition of 2D and 3D vector fields?

I have a sample of 100 particles with their 3D positions and velocities. I want to decompose the velocity vector field to its curl free and divergence free components. Is it a feasible to do so for ...
4
votes
0answers
205 views

MATLAB: solving multiple ODE systems in parallel

I have a system of parameterized ODEs that I would like to solve using MATLAB and its ode45 solver, and was wondering if it is possible to perform such a task in ...
0
votes
1answer
318 views

How to implement an integral condition when solving a BVP in MatLab

I am trying to solve a coupled system of ODE's using MATLAB's bvp4c function. I want to impose the condition that $$\int_{0}^{\pi} y_{1}(t) y_{1}(t) dt = 1,$$ where ...
1
vote
0answers
119 views

Estimate $L_2$ norm of a elliptic problem with unknown exact solution on finite element method

I have the elliptic problem $$-\Delta u = 1,\,\,\Omega\subset\mathbb{R}^2$$ with $u=0$ on $\partial\Omega,$ with $\Omega=[-1,1]^2\backslash([0,1]\times[-1,0])$ and I want to estimate the $L_2$ error ...
0
votes
3answers
2k views

What is the difference between MATLAB and FORTRAN?

In our university some Ph.D students for computational methods prefer FORTRAN over MATLAB. I can't understand why? What is the difference between them when are used in computational methods like ...
1
vote
1answer
139 views

Trouble getting steady-state solution by solving system of nonlinear algebraic equations in MATLAB

Background I have a stiff system of 6 ODEs, represented in MATLAB as follows: ...
0
votes
2answers
216 views

Random walk on lattice

I have a $9 \times 9$ square lattice. In each site of the lattice, there are $N$ molecules, where $N$ is a large random number and it is different for different sites. N equal to 100000000+-100 in ...
1
vote
0answers
115 views

Eigenvalues using QR iteration

I'm trying find the eigenvalues of a matrix A using QR iteration with Householder. I used this code which I found from Cornell University that decomposes QR with Householder. ...
1
vote
2answers
421 views

MATLAB FFT Differentiation

I am trying to implement the Laplacian operator using Fourier Transform differentiation (https://en.wikibooks.org/wiki/Parallel_Spectral_Numerical_Methods/...