Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

Filter by
Sorted by
Tagged with
0
votes
0answers
32 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
1answer
64 views

Multi-domain 3D Geometries for MATLAB PDE Toolbox

In principle the PDE Toolbox in MATLAB can handle multi-domain 3D geometries as noted here. This feature and the associated function geometryfromMesh were introduced in MATLAB R2018a. The associated ...
0
votes
0answers
24 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 ...
1
vote
0answers
19 views

Using nondimensionalization to solve an ode in MATLAB [duplicate]

I am trying to solve an ode that uses some extremely large numbers and some extremely small numbers, namely $$ e = 1.6\times 10^{-19}\\ E = 10^6\\ \tau = 6\times 10^{-24}\\ m = 9.1\times 10^{-31}\\ c ...
2
votes
1answer
26 views

How to store all solutions of an ODE on Matlab for multiple values of a parameter

I would like to solve an ODE for multiple values of the parameter p and most importantly, save all the solutions for all the different values. Till now, I have ...
2
votes
1answer
61 views

MATLAB's ode45 not dealing with initial conditions well [RESOLVED]

*Concern highlighted in yellow *Solution at bottom I have a differential equation to solve for the motion of an electron: $$ \frac{d^2v}{dt^2} = \frac{1}{\gamma^6}\left( \frac{eE}{\tau m} - \left( \...
-1
votes
1answer
20 views

Plot sinewave on ZX axis [duplicate]

I am trying to plot a sinewave with a bit of 3d perspective along the ZX axis instead of the XY axis. I have so far been unable to get anything that works, and have been unable to locate any examples....
1
vote
0answers
45 views

Using MATLAB to simulate the Ising Model

I am using MATLAB to simulate a 1D Ising Chain. I am running into an issue where when trying to find heat capacity, my system has a tremendous amount of noise. I'll post my code and an image of the ...
2
votes
3answers
104 views

Is there any other sparse matrix data in matlab built-in file?

I want to do some numerical examples solving large sparse linear system Ax=b. And I want to use some data from Maltab itself because this experiments are easily ...
3
votes
0answers
49 views

Why GA convergence curves continue as two parallel lines?

I'm working on a optimization problem and using GA algorithm (in MATLAB, ga function). As you know MATLAB plots GA result with two curves, one for the best values and other to show the mean values ...
2
votes
1answer
52 views

Defining Current Density in a FEM model (MATLAB)

I'm attempting to solve the Poisson equation in 3D for a magnetic vector potential in the presence of a current source. To validate my code, I'm initially looking to reproduce the model described in ...
0
votes
0answers
39 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 ...
1
vote
1answer
64 views

Solving 1D convection using method of lines

I'm interested in solving the following 1D-advection equation using method of lines. $$\frac{\partial C}{\partial t} = - v\frac{\partial C}{\partial x}$$ The spatial domain has been discretized into ...
0
votes
0answers
28 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 ...
1
vote
2answers
50 views

What's the difference between the 2 ways of definitions of function handle? which is robust and better?

Recently, I have been studying Krylov subspace iterative methods. I find the matlab robust command pcg and the new concept of the function handle to return a matrix-vector product. Then I use help pcg ...
2
votes
3answers
107 views

How the gmres method iteration behaves for this **enfant terrible** matrix?

Recently, I have been studied my lessons about gmres iteration, probably the most popular iteration method for general large sparse linear system of equations Ax=b. And the convergence is obtained ...
0
votes
0answers
15 views

Offline Parameter Estimation for second order system - Ordinary Least Squares

I have a second order system which is described by the following differential equation: $\ \ddot{y}+α_{1}*\dot{y}=b_{0}*u $ where $\ y $ is the output of the system and $\ u $ is the input of the ...
1
vote
1answer
51 views

What is the format of saving sparse matrix in MATLAB?

We know that for lagre sparse matrices, we can use compressed sparse row (CSR) or compressed sparse column (CSC) format to store the sparse matrices so that we can save CPU memory. And the coordinate ...
0
votes
0answers
22 views

Interpreting results of using no-flux boundary condition

I am solving for solute transport in 1 D. $$\frac{\partial C}{\partial t} = D\frac{\partial ^2 C}{\partial x^2} - v\frac{\partial C}{\partial x}$$ No-flux boundary condition is imposed at both the ...
1
vote
0answers
59 views

Solving diffusion equation using finite difference method

I am solving an 1-dimensional diffusion equation with Neumann boundary condition at outlet and constant concentration, C, at the inlet. In the end, I want to observe how the concentration diffuses ...
2
votes
0answers
79 views

Extracting FEM matrices in matlab pde toolbox

I am trying to follow the dynamic linear elasticity in Matlab, link here. My goal is to extract the FE Matrices using the function assembleFEMatrices in matlab and solve the resulting system of second-...
-3
votes
1answer
81 views

Does a new proposed method for solving Ax=b must beat matlab command 'A\b' be a successful method?

I have a question about direct and iterative method. Many people including me often say that for very large sparse linear system, Ax=b, an iterative method is necessary because of cpu memory. I also ...
0
votes
0answers
31 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
1answer
45 views

Shooting Method- Boundary value problem starting from -1 to 1

The equation is $\rho \frac{d \bar{u}}{dy} = -\frac{d\bar{p}}{dx} + \mu\frac{d^2\bar{u}}{dy^2} $ with boundary condition $u(-1)=0$ and $u(1)=1$ I am to solve it using fifth order runge-kutta ...
0
votes
0answers
21 views

Controllability - Maximum Matching

I found this image on wikipedia referring to Barabasi's work on Network Controllability. I tried to verify it. We have a A matrix of dimensions (20 by 20) made as the image suggests. According to the '...
1
vote
1answer
53 views

How to avoid unnecessary checks when inverting this LU decomposition

Background for the question I am currently working on a Matlab code in which the systems of linear equations $Ax_1 = b_1$, $Ax_2 = b_2$, ... have to be solved. As the matrix $A$ is constant during ...
2
votes
1answer
46 views

Passing data as arguments in ODE45

I need to import data from file in order to describe the structure of a network. I used the following: weights = readtable('weights192.txt'); W = weights{:,:}; ...
2
votes
1answer
72 views

1-D boundary value problem: How implement mixed boundary conditions using a FD method?

I have been given a convection-diffusion ODE modeling the steady state temperature of a pipe (through which flows a fluid) as $$-\frac{d}{dz}\left(\kappa \frac{dT}{dz} \right)+v\rho C\frac{dT}{dz}=Q(...
3
votes
2answers
85 views

ode45 with matrix initial conditions

EDIT: We have a coupled system of 10 ode each. The coupling presents in the last equation. I thought about using a matrix 10 by 2 as initial conditions. I also followed a similar question with the ...
2
votes
2answers
155 views

Why iterative method: AMG preconditioned PCG is slower than Matlab direct method 'A\b'?

Recently, I have met a question that a saying goes that for large linear system: iterative methods are required because of memory problem of direct methods. But when I implement some experiments ...
1
vote
1answer
59 views

How to use QZ decomposition for single matrix in Matlab?

Can I use QZ decomposition on a single square matrix in Matlab? Like, [Aa,Q,Z]=qz(A);
0
votes
0answers
63 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 ...
1
vote
0answers
36 views

How to set the errorbars in a different color from the plot in Matlab? [closed]

When making a plot in Matlab using errorbar(...) the color of the error bars is the same as the plot. How do I set them to be in a different color? I tried looking ...
0
votes
0answers
72 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 ...
1
vote
1answer
72 views

How to implement this even-odd matrix decomposition efficiently?

Note: This question has also been asked on stackoverflow - see https://stackoverflow.com/questions/57197910/how-to-implement-this-even-odd-matrix-decomposition-efficiently?noredirect=1#...
12
votes
2answers
2k views

What is the most efficient way to write 'for' loops in Matlab?

I have read that if, for example, I have a double for loop that runs over the indexes of a matrix, then putting the column running index in the outer loop is more ...
0
votes
0answers
62 views

How to make this parfor loop work properly in Matlab?

I have a code that does some calculations for a given value p (p is between 0 and 1). In theory I should be able to make a parfor loop that runs over the values of p, with p being a vector (for ...
2
votes
1answer
38 views

How to pass matrices to parallel workers quickly in matlab?

I am trying to solve many different linear systems in parallel in matlab. The problem is, each linear system has entirely different parts and are fairly large, so passing the information to each of ...
3
votes
1answer
157 views

calculation of the right hand side of DG FEM (with code)

I got stuck with Hestaven/Warburton's dG-FEM Matlab code. Starting with the file AdvecRHS1D.m, we see in line 11 ...
2
votes
0answers
15 views

Why I am not able to generate Levy distribution using inverse transform method on MATLAB?

I am trying to generate random numbers using Levy distribution in MATLAB. I am using the inverse transform method to generate random numbers and then plot its histogram for pdf estimation. Then I ...
2
votes
0answers
67 views

How to solve $y(x) y'''(x)=f(x)$

I have a PDE of the form $\partial_t y(x,t)+\partial_x(y(x) y'''(x)-f(x))=0$, where $f(x)=\cos(x)$. Suppose a stable equilibrium exists, and I want to find the steady-state solution $y(x) y'''(x)=f(x)...
15
votes
5answers
1k views

Why does the numerical solution of an ODE move away from an unstable equilibrium?

I wish to simulate the behaviour of a double-pendulum-like system. The system is a 2-degrees-of-freedom robot manipulator that is not actuated and will, therefore, behave mostly like a double-pendulum ...
0
votes
0answers
65 views

Computing a double Integral using two Riemann sums & graphing multiple isosurfaces

I'm trying to compute the potential and electric field of a uniformly charged spherical shell and plot the results in the space outside the shell using MATLAB. I've tried everything from for loops to ...
3
votes
2answers
163 views

Graphing electric potential of a ring of charge using MATLAB help

Here is a summary of what I am trying to do: Use MATLAB to compute the potential $V$ at any point $(x, y, z)$ in space due to a uniform ring of charge. Use a Riemann sum to compute the integral ...
0
votes
0answers
29 views

Execution time of cumulative integral

In Matlab, we have the cumtrapz function, which returns the approximate cumulative integral of y: I = cumtrapz(x,y) This ...
0
votes
1answer
45 views

How to do Weierstrass-transform in MATLAB?

I have a diagonalization problem. I have the eigenstates correctly, and I want to do a Gaussian-smearing (Weierstrass-transform) on them. So I have the wave functions ($\Psi$), and the continuous ...
0
votes
0answers
28 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
23 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
44 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-...
1
vote
1answer
55 views

Online Parameter Estimation using steepest descent

I have a first order system which is described by the following differential equation: dx/dt = -a*x + b*u where u is the input <...