Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

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

Floating Point error when computing Binomial Distribution Probability

I have been given a binomial distribution: $$B(m+n;n,p)=\frac{(m+n)!}{m!n!}p^mq^n.$$ Here $m = 10^3$, $n=10^2$, $p=10^{-2}$, $q=1-p.$ I'm using MATLAB to compute log $B(m+n;n,p)$ and store the value ...
1
vote
2answers
61 views

Solution of symmeric/non-symmetric linear system

I would like to understand what happens in the following: I have a really simple Poisson problem, in 1D, with $u_0 = u_N = 0$. I assembled the stiffness matrix and the right-hand side, and I applied ...
1
vote
1answer
41 views

How to write a code of 2D ADI method in matlab?

I tried to write a code for ADI method in 2D, but I got stuck. My equation is: $$\frac{\partial U(t,x,y)}{\partial t} = 2\Delta U(t,x,y) -10(\frac{\partial U(t,x,y)}{\partial x} + \frac{\partial U(t,...
0
votes
1answer
32 views

MATLAB ode45 doesn't start at initial conditions

I wrote a code in MATLAB to solve a system of differential equations, but my solution doesn't seem to take into consideration the initial conditions I specified. I am not sure how to interpret this ...
0
votes
0answers
27 views

Implementation of nonlinear optimization for Generalized Nash-Equilibrium

I have to find a solver for $\begin{equation} \min_{x^{\nu}} \Theta_{\nu}(x^{\nu},x^{-\nu}) \end{equation}$ with $x^{\nu} \in X_{\nu}$ which is a convex set. $x^{*}$ needs to satisfy $$\nabla_{x^{\nu}...
0
votes
1answer
54 views

Efficient way to store array where elements are added and removed frequently

At any point in time I have a list of N points, points will be added and removed making the number of total points change over time. If I just use an array to store this information, I'm concerned ...
1
vote
0answers
18 views

Finding isocontour lines, populating points on said lines (in MATLAB)

I'm trying to extract data from a potential field. I have an example code of a potential field, using meshgrid in MATLAB. I've pasted the code below. What I'd like to do next is 'convert' this field ...
0
votes
0answers
22 views

More efficient way of solving for transfer function between boundaries of wave equation

I am considering the wave equation with position varying material properties $$ m(x) \frac{\partial^2 u}{\partial t^2} = \frac{\partial}{\partial x}\left(k(x) \frac{\partial u}{\partial x}\right), \...
0
votes
0answers
17 views

Convex performance measure of classification

In the context of binary classifcation methods, I am looking for a performance metric that can be optimized in MATLAB. Since the data is not balanced, a good choice seems to be the so-called F1-...
1
vote
0answers
25 views

How does Block-diagonal Schur factorization in Matlab works?

Can anyone explain how does the bdschur command of Matlab works? And how should the CONDMAX and ...
1
vote
1answer
82 views

Efficient Arbitrary Order Finite Differences in 1D

I am implementing on Matlab a high-order finite differences scheme to approximate the first derivative of $f(x_i)$ given $x = [x(1), x(2),..., x(i),..., x(n)]$ and $f = [f(x(1)),..,f(x(n))]$ with $x$ ...
1
vote
1answer
46 views

Using Axis Equal for Matlab simulation plots of the SIR model gives very flat solution curves

My professor taught us to always use the Matlab command axis equal for our simulation data plots - for all of our homework assignments. However, in studying the ...
2
votes
0answers
46 views

Modelling of Stefan Maxwell equation

I am trying to solve Maxwell Stefan's equation over a membrane to get the transient mole fraction distribution over the membrane thickness 'z'. But somehow I am not able to code it using ODE45, more ...
0
votes
2answers
61 views

Reorder eigenvalues in Schur factorization in descending order

In this command: [US,TS] = ordschur(U,T,select) what should replace the select to rearrange the eigenvalues in descending ...
1
vote
1answer
56 views

When is a dynamical system discrete vs. continuous?

I have a basic question to ask: Let's say I am reading a paper which gives a good model that consists of a set of ordinary differential equations, with first and second derivatives. Continuity is a ...
2
votes
0answers
42 views

How to determine the finite difference coefficient matrix in 2D with periodic BC?

I'm solving a PDE in matlab using ode15s, and since the spatial dimension is 2, and number of variables grow large very quickly, I need to supply the structure of ...
2
votes
1answer
65 views

Crank-Nicholson scheme for transport equation

This is my attempt to find the approximate solution of the folowing transport equation $$\left\{\begin{array}{ll} \partial_{t} u+\partial_{x} u= (x^2-x)t+x^3/3-x^2/2, & t \in(0,0.4), x \in(0,1) \\ ...
1
vote
0answers
39 views

Inverse Newton Method for optimization: is this the correct algorithm?

I am trying to implement the algorithm in this article. I have already asked a question before about it here, and I am trying to figure out what I am doing wrong. This time, it's this section of the ...
3
votes
0answers
109 views

Automatically generate constraints for trajectory optimization

This is a follow up to my previous post here I'm interested in performing trajectory optimization from the problem mentioned in abov link. I want to supply the following as dynamical constraints to ...
1
vote
2answers
100 views

Solving a parameter estimation problem using trajectory optimization

This is a follow-up to my previous question here I've the following system of equations for studying information flow in the below graph, $$ \frac{d \phi}{dt} = -M^TDM\phi + \text{noise ...
-1
votes
1answer
89 views

If not MATLAB, what software/programming language should I use to simulate/animate wave functions in various potentials + more? (example given)

I want to integrate programming into my learning in math and science in a very specific way. I want to create visualizations and simulations of concepts I am learning. When I learn a numerical method ...
2
votes
1answer
131 views

Question on how MATLAB's pdepe solver works

I'm solving the following 1D transport equation in MATLAB's pdepe solver. $$\frac{\partial C}{\partial t} = D\frac{\partial ^2 C}{\partial x^2}-v\frac{\partial C}{\partial x}$$ At the inlet (left ...
4
votes
2answers
199 views

Fastest Way to Mutiply $10^4$ 2x2 Matrices

In a code that I work with (written in python, but also tagging as matlab because numpy is so close and I could use it if need be), we use a transfer matrix method to compute the properties of a ...
4
votes
2answers
126 views

Effect of mesh size on solution curves for a 1D problem

I'm interested in studying the effect of mesh size on the behavior of the solution curves of 1D convection-diffusion problem. $$\frac{\partial C}{\partial t} = D\frac{\partial ^2 C}{\partial x^2} - ...
3
votes
2answers
191 views

Solving ODE with “Jumpy” Coefficients

I'm numerically solving a linear coupled ODE of the form $$y^{\prime}(t) = \hat{M}(t)y(t)=\left[\begin{array}{cc}0& A(t)\\ B(t)& 0\end{array}\right]y(t),$$ and the difficulty I'm running into ...
1
vote
2answers
88 views

How to understand the storage of the Hessenberg matrix of Krylov subspace matrix?

For the Krylov subspace method to solve the large sparse linear system, we first need to generate a subspace Km = span{v,Av,...A^{m-1}v}, which indeed a process ...
-1
votes
1answer
88 views

Finding derivative of Matrix at different grid points using Finite difference methods/ Cholesky Factorization

I want to code this problem in MATLAB. It would be a huge help if someone can suggest to me how I can approach it. I need to solve the below-highlighted equation, I need ...
0
votes
0answers
42 views

How to implement the gmres method using Householder transformation instead of the Gram-Schmidt?

For Generalized Minimal Residual method GMRES, we usually use the Modified Gram-Schmidt MGS to generate an orthonormal basis of ...
4
votes
0answers
58 views

Why the two Gram-Schmidt algorithms produce different results for qr factorization?

For the qr factorization using classic Gram-Schmidt algorithm, I found the 2 different implementations below. The first one uses the for loop to compute the upper ...
2
votes
1answer
72 views

pdepe or Crank-Nicolson? How much is pdepe good?

I am beginner in MATLAB and similar. I sow and discussed with my professors doing simulations some times: they wrote down a lot of calculus, most of them using Crank-Nicolson Method and so implement ...
4
votes
1answer
78 views

Why the solid FEM problem can not be solved after constraining 3 degrees of freedom?

I write a simple MATLAB code for solving solid FEM problem. The problem looks like that (1) (2) x-------x | / | | / | | / | x-------x (3) (4) ...
33
votes
2answers
12k views

why is A*v+B*v faster than (A+B)*v?

$A$ and $B$ are $n \times n$ matrices and $v$ is a vector with $n$ elements. $Av$ has $\approx 2n^2$ flops and $A+B$ has $n^2$ flops. Following this logic, $(A+B)v$ should be faster than $Av+Bv$. Yet,...
0
votes
2answers
49 views

contour plot of cloud of points [closed]

I have a cloud of points scattered in a rectangle and some data in this points, a bit like this $$ x(:)=[x(1), x(2), ..., x(N)] \\ y(:)=[y(1), y(2), ..., y(N)] \\ u(:)=[u(1), u(2), ..., u(N)] $$ ...
0
votes
0answers
69 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
2answers
104 views

What's a nice simple PDE to play with in Matlab?

I want to learn a very simple PDE to gain physical and mathematical intuition—a PDE with just one spatial dimension $x$ and a time dimension $t$. And, I want to write code for it in Matlab and use a ...
2
votes
1answer
89 views

Solving system equation

Given matrix $K_{n \times n}, H_{n \times n},M_{n \times n}$, I want to solve for $B_{n \times n} $ and $V_{n \times 1}$ from the nonlinear system of equations: \begin{aligned} &H_{i j}=\frac{B_{i ...
11
votes
3answers
4k views

How much more work is it to code math models in Python, compared to working with Matlab?

If one had to code up a new dynamical system for a research group at a university, and the university has a Matlab total headcount license so that one could code in Matlab, are there any benefits to ...
2
votes
1answer
50 views

Could the convex problem be tackled by CVX?

I want to solve the convex optimization as follows: \begin{align} \underset{X_1,X_2}{\min} &\ -\frac{1}{N}\sum_{i=1}^N\log\det\left(I+H_i^HX_2H_i\right)-\log\left[1+h^H(X_1+X_2)h\right]\\ &\...
2
votes
1answer
268 views

How to implement flexible gmres in matlab?

About the flexible GMRES (fgmres), we know that it is a variant of right preconditioned gmres. And the robust command gmres in matlab as follows: ...
0
votes
0answers
42 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
221 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
32 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
20 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
38 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
89 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
59 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
151 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
55 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 ...
0
votes
0answers
46 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
2 3 4 5
14