Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

Filter by
Sorted by
Tagged with
2
votes
2answers
91 views

Generate random smooth 2D closed curves

I would like to know how can I generate a collection of random 2D closed smooth curves. I thought about generating a random 3D surface with random peaks, and then intersecting the Z=0 plane with it, ...
3
votes
1answer
142 views

Solving the heat diffusion equation with source term

I am trying to solve the 1-D heat equation numerically with a variable source term. The system is basically a tank containing styrene in which it polymerizes to liberate heat. I have assumed that the ...
2
votes
0answers
51 views

Determine the anti-derivative of 2D vector field

I have data on a (x,y) grid with scalar values (time) at each point. I have used the numpy gradient function and linear interpolation to determine the gradient vector Velocity (Vx,Vy) at each point (...
0
votes
1answer
44 views

How to optimize nuclear norm subject to positive semidefinite constraints?

For finite dimensional symmetric positive semidefinite matrices $A$ and $B$, I would like to solve \begin{align}&\min |X - A|_1 \\ &\text{subject to}\\ &X \preceq B \\ &0 \preceq X\...
1
vote
1answer
40 views

How to effectively find a starting point solving a non-linear equation?

I have the following equation (the Kurz-Giovanola-Trivedi model [1]) $$ v^2 \frac{\pi^2 \Gamma}{P^2 D^2} + v \frac{mC_0(1-k)\xi}{D[1-(1-k)Iv(P)]} + G = 0, $$ where $Iv(P)=P \cdot \exp(P) \cdot E(P)$, $...
3
votes
1answer
111 views

Scaling/Performance of Matlab's svds function (Lanczos bidiagonalization)

I have a simple Matlab script which aims to compute $k$ singular values of a matrix $A$. $A$ is a random dense square matrix of size $5000\times5000$, with 100 of its singular values constrained to ...
1
vote
2answers
67 views

How do I speed up this function evaluation in matlab?

Half the run time of my code right now is evaluating a big function over many, many points, it takes maybe about 20 seconds per evaluation The function consists of a bunch of simple operations that ...
-1
votes
0answers
35 views

Matrix Calculation Different between Python and Matlab

I am transferring a finite element code from Matlab to Python. A problem occurs at the last step when I try to solve the displacement $U = F/K$. I have checked that the calculated $F$ and $K$ are same ...
0
votes
2answers
61 views

Uniaxial stretching solution not uniform in FEM code

I am trapped here for a long time. I wrote a toy Matlab FEM code. I want to run the follow simulation. Mesh Suppose we have a cube, and we divide it into subcube along $x,y,z$ axis, then each subcube ...
1
vote
1answer
90 views

Matlab - Fast Computation of Truncated SVD / PCA

I'm working with a Matlab codebase wherein I'm attempting to solve A*c = b by approximating the (square) matrix A with its ...
0
votes
0answers
49 views

Non-linear differential equation

I have this equation $$y\left(\dot y^2+1\right)=m + \Lambda y^3,$$ where $\Lambda=1.1\cdot 10^{-52} $ (Cosmological constant). I want to get the graph of the solution of this equation (2-parametric ...
2
votes
1answer
186 views

Solution of the linear system using Sherman-Morrison formula for 1000000x1000000 (7450.6GB) matrix using MATLAB

Let $n = 10^6.$ Let $A \in \mathbb{R}^{n\times n} $ be the lower triangular matrix having 1's on and below the main diagonal. We want to solve the following linear system: $$ (A + uv^T)x = b$$ by the ...
1
vote
1answer
44 views

Bode diagram without bode() function

Is there any way to make a bode plot without using the MATLAB/GNU Octave function bode()? As an example, here is a function I am working on: $$H(s) = \frac{1}{2s^...
0
votes
1answer
58 views

Plotting the difference between an exponential and its Taylor expansion as a function of number of terms?

I'm terribly green, please forgive me. I need to plot the difference between a chosen calculated Taylor expansion $e^x=1+x+\frac {x^2}{2!}+\frac {x^3}{3!}+\frac {x^4}{4!}+\frac {x^5}{5!}$... and the ...
1
vote
0answers
146 views

Two-dimensional modelling of a flate-plate reactor

I am trying to simulate the unsteady pollutant concentration along the reactor by solving the 2nd order PDE below with the stated BC and IC. which method is appropriate to solve convection-diffusion-...
1
vote
2answers
79 views

Rewriting matrix multiplication

I have a matrix multiplication in Matlab that goes as follows $$\hat{W} = N W N^{T},$$ where $^T$ means a transposition. $N$ is an incidence matrix with the dimensions m x n and W = diag(G), where G ...
0
votes
0answers
26 views

Simulating the response of nonlinear system with stiff differential equations

I want to simulate the response of a nonlinear system given in the following form: $$ \dot{x_1} = f_1(\bar{x_1})+g_1(\bar{x_1})x_2, \ x_1(0) = 0.2 $$ $$ \dot{x_2} = f_2(\bar{x_2})+g_2(\bar{x_2})x_3, \...
0
votes
1answer
37 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 ...
2
votes
2answers
83 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
73 views

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

I tried to write a code for the alternating direction implicit (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)...
0
votes
1answer
33 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
29 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
57 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
20 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
29 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
18 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
83 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
48 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
68 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
57 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
74 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
121 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
107 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
92 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
150 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
204 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
128 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
197 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
91 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
57 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
59 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
83 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
81 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)] $$ ...

1
2 3 4 5
15