Stack Exchange Network

Stack Exchange network consists of 175 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]

For mathematical questions about MATLAB; questions purely about the language, syntax, or runtime errors would likely be better received on Stack Overflow. MATLAB is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks.

4
votes
3answers
22k views

How to plot a phase portrait for this system of differential equations?

I beg your help.. I'd like the phase portrait for this system: \begin{aligned} \frac{dx}{dt} &= x (7-x-2y) \\ \frac{dy}{dt} &= y (5-y-x) \end{aligned} I don't know how to use Mathematica/...
1
vote
3answers
334 views

Numerical estimates for the convergence order of trapezoidal-like Runge-Kutta methods

I have to calculate approximations of the solution with the method $$ y^{n+1}=y^n+h \cdot [\rho \cdot f(t^n,y^n)+(1-\rho) \cdot f(t^{n+1},y^{n+1})] ,\quad n=0,\ldots,N-1 \\ y^0=y_0 $$ for various ...
30
votes
5answers
52k views

How to generate random symmetric positive definite matrices using MATLAB? [closed]

Could anybody tell me how to generate random symmetric positive definite matrices using MATLAB?
9
votes
2answers
5k views

Fast Matlab Code for hypergeometric function $_2F_1$

I am looking for a good numerical algorithm to evaluate the hypergeometric function $_2F_1$ in Matlab (hypergeom in Matlab is very slow). I looked across the ...
2
votes
1answer
478 views

Creating an ellipsoidal 3D surface

I am trying to find the equation of a 3D ellipsoidal surface. I have thought of two approaches which are schematically shown below: By revolving an elliptical arc over a 3D elliptical path: Or by ...
18
votes
2answers
16k views

Implementing Ornstein–Uhlenbeck in Matlab

I am reading this article on Wikipedia, where three sample paths of different OU-processes are plotted. I would like to do the same to learn how this works, but I face troubles implementing it in ...
5
votes
1answer
14k views

heat equation with Neumann B.C in matlab

$$ \frac{\partial u}{\partial t}=\alpha\frac{\partial^{2}u}{\partial x^{2}} \qquad u(x,0)=f(x)\qquad u_{x}(0,t)=0\qquad u_{x}(1,t)=2 $$ i'm trying to code the above heat equation with neumann b.c. ...
10
votes
2answers
46k views

Piecewise function plot in Matlab

Is it possible in Matlab to plot an even piecewise function like: $ f(x) = \begin{cases} 3t , 0 < t < \pi \\ -3t , -\pi \le t \le 0 \end{cases}$ which has a period of $2\pi$. I can'...
6
votes
2answers
12k views

Evaluate derivative of Lagrange polynomials at construction points

Assume, that we have points $x_i$ with $i=1,...,N+1$. We construct the Lagrange basis polynomials as \begin{align} L_j(x) = \prod_{k\not = j} \frac{x-x_k}{x_j-x_k} \end{align} Now according to my ...
3
votes
3answers
87 views

Determine which of $N$ points is not on $\sin(ax + b)$, where $a$ and $b$ are unknown.

Suppose $N$ points ($(x_1,y_1), (x_2,y_2), ... (x_N,y_N)$) are given from a curve $y=\sin(ax+b)$ where $a, b$ values are unknown. Before giving these $N$ points to you, $y$ coordinate of one point is ...
2
votes
1answer
190 views

Matlab questions about $a_{n+1} = 4a_{n} + n +1$

Solve the equation with Matlab Given: $a_{n+1} = 4a_{n} + n +1$ Start condition: $a_{i}=0$ Questions: a) Find x,y for: $b_{n} = a_{n}+xn+y$ such that: $b_{n+1}=4b_{n}$ b) Find an explicit ...
0
votes
1answer
168 views

Matlab's “buggy” symbolic integration function seems to be equivalent to the Implied Integral. Coincedence or intentional?

In matlab there is a function called "int(f,x)" which takes in a symbolic function and a variable and integrates it. I decided to try using it today to play around and do a few integrals and I got a ...
0
votes
1answer
4k views

Tensor double dot product [closed]

I have two tensors that i must calculate double dot product. matrix A is rank 2 and matrix B is rank 4. I want to multiply them with Matlab and I know in Matlab it becomes: A : B = trace (A*B) but it ...
3
votes
1answer
818 views

Projection Matrix onto null space of a vector

I have a vector summation $x_1 + Ax_2$ where $x_1\in\mathbb{R}^{n\times1}$, $A\in\mathbb{R}^{n\times m}$ and $x_2\in\mathbb{R}^{m\times1}$. I am wondering if I can find a projection $P\in\mathbb{R}^{...
1
vote
1answer
205 views

Economic price optimisation problem

I am looking to solve an economic system, using Matlab. It considers an industry of just 2 firms where the demand functions for Firm 1 and Firm 2 are: $$q_1(p_1,p_2)=\alpha(p_1-\delta p_2)^{-\gamma},$...
0
votes
1answer
774 views

Euler method for SIR model

I know how to solve SIR model with ode45, but I just wanted to try it out using Euler Method. The SIR model is: $\dot S=-\beta IS \\ \dot I = \beta IS - \gamma I \\ \dot R = \gamma I$ The code that I ...
0
votes
1answer
126 views

Matlab Recursion Loop

I need to create a loop to answer part c of the following linear algebra question. I'm new to Matlab so this is extremely confusing. I'm not sure how to make a loop that "counts" from 0-25 in order to ...
0
votes
1answer
723 views

Solving a system of two second order ODEs using Runge-Kutta method (ode45) in MATLAB

I'm trying to solve the system of differential equations outlined in Von Karman's rotating disk flow. I got them into a system of ordinary differential equations: F(n), G(n), H(n) $$F'' = -G^2 + F^2 ...
0
votes
1answer
146 views

Can we say something about the rows of the null space matrix

I have $x_1=Mx_2$ where $x_1\in\mathbb{C}^{q\times1}$, $M\in\mathbb{C}^{q\times p}$ and $x\in\mathbb{C}^{p\times1}$. Then we have $M:\mathbb{C}^{p}\longrightarrow \rm{Range}(M)$ and we know that $\...
-2
votes
0answers
72 views

Writing systems of linear equations and matlab help appreciated [duplicate]

Does anyone know how I would go about answering the following question? A traffic engineering company has installed some trac cameras along a one lane road to find a relation between the number of ...
11
votes
2answers
1k views

What is the difference between optimal control and robust control?

What is the difference between optimal control and robust control? I know that Optimal Control have the controllers: LQR - State feedback controller LQG - State feedback observer controller LQGI - ...
12
votes
3answers
774 views

What function could describe this GIF animation?

I found this image on Beautiful Mathematical GIFs Will Mesmerize You and this GIF really caught my attention. From what I see, it's a 2D circle morphing into the 3D sphere. What function could ...
11
votes
1answer
11k views

Expected Value and Variance of Monte Carlo Estimate of $\int_{0}^{1}e^{-x}dx$

Given the integral: $I=\int_{0}^{1}e^{-x}dx$, use standard Monte Carlo with 1000 random numbers and repeat the simulation 1000 times. (a) What is the expected value and variance of the simple Monte ...
4
votes
3answers
2k views

Parametric equations and specifications of a triskelion (triple spiral)

I haven't been able to find the parametric equations and specifications to form a triskelion, a triple spiral (this is made of three interlocked couples of spirals). Using the parametric equation of ...
3
votes
0answers
3k views

Please help: My MATLAB code for solving a 2D Schrödinger equation keep giving me weird output. [closed]

I've been trying to solve the following Schrödinger equation numerically, \begin{equation} -(\frac{\partial^2}{\partial y^2} + \frac{\partial^2}{\partial z^2})\Psi + \frac{\sinh^2(y) + \sinh^2(z)}{(\...
5
votes
3answers
1k views

Solving Viscous Burgers using spectral method

I am trying to solve the Viscous Burgers equation using the spectral method. $$u_t+uu_x = Du_{xx}$$ where $D$ is a constant (chosen to be zero) and with the initial condition $$u(x,0) = exp(-x/0.2)^2$$...
7
votes
1answer
12k views

Derivative of function using discrete fourier transform (MATLAB)

I'm trying to find the derivative of a function $f(t)$ using the discrete fourier transform. My end goal is to do so numerically, but I suppose if I have the theory down then the rest should follow ...
6
votes
3answers
6k views

How to calculate $\exp(-x)$ using Taylor series

We know that the Taylor series expansion of $e^x$ is \begin{equation} e^x = \sum\limits_{i=1}^{\infty}\frac{x^{i-1}}{(i-1)!}. \end{equation} If I have to use this formula to evaluate $e^{-20}$, how ...
6
votes
1answer
8k views

Matlab code for finding the curvature of a curve using given data points

I have data points $(x,y)$ for a plane curve, and I would like to find its curvature. While I was googling to check how could I start, I found this matlab code: ...
5
votes
1answer
185 views

Solve Boundary Value Problem for $y''+ y' + e^xy = f(x)$

Consider to solve Boundary Value Problem : $y''+ y' + e^xy = f(x)$ with $0 < x < 1$ and $y(0)=y(1)=0$ with exact solution $y(x) = \sin \pi x$ $f(x)=(e^x- \pi^2)\sin \pi x + \pi \cos \pi x$...
4
votes
1answer
4k views

How to compute elliptic integrals in MATLAB

I need to calculate the complete elliptic integrals of the first and second kind , the incomplete elliptic integral of the first kind, and the incomplete elliptic integral of the second kind in MATLAB....
4
votes
1answer
185 views

If $X$ is symmetric, show $k(X^2)$ = $k(X)^2$

Suppose we have a symmetric invertible matrix $X$. How can I find $k(X^2)$ in terms of $k(X)$? Note that $k$ represents the condition number operation, that is $k(X) = \|X\|\,\|X^{-1}\|$. So, after ...
4
votes
2answers
337 views

Finding analytical solutions for given equations

I have a system of 6 equations with 6 variables. The 6 variables are $t11, t12, t13, t21, t22, t23$ and the rest of the symbols in the equations are known symbols. I want to find all the possible ...
3
votes
1answer
909 views

Switching from Mathematica to MATLAB: As a text editor?

I have been using Mathematica for almost a year, and the most indispensable feature in Mathematica to me has been the ability to write really nice documents and print them into PDF or TEX files. In ...
2
votes
1answer
38k views

Solving a system with Newton's method in matlab?

I have the following non-linear system to solve with Newton's method in matlab: x²+y²=2.12 y²-x²y=0.04 What is the linear equation system to be solved? Should I ...
1
vote
1answer
140 views

Solve advection equation $v_t + v_x = 1$ numerically with Matlab

Consider the advection equation $$ v_t + v_x = 1 $$ with initial condition $$ v(x,0) = \begin{cases} \sin^2 \pi (x-1), & x \in [1,2] \\ 0, & \text{otherwise} \end{cases}$$ Clearly, we ...
23
votes
3answers
3k views

Matlab wrong cube root [closed]

How can I get MATLAB to calculate $(-1)^{1/3}$ as $-1$? Why is it giving me $0.5000 + 0.8660i$ as solution? I have same problem with $({-1\over0.1690})^{1/3}$ which should be negative.
7
votes
0answers
455 views

Problem with an algorithm to $3$-colour the edges of cubic graphs

I'm currently trying to implement an algorithm to $3$-colour the edges of cubic graphs. (I want to do this with Matlab's Symbolic toolbox). After restricting to planar graphs to ensure the existence ...
6
votes
1answer
1k views

How to use Newton's method to find the roots of an oscillating polynomial?

Use Newton’s method to find the roots of $32x^6 − 48x^4 + 18x^2 − 1 = 0$ accurate to within $10^{-5}$. Newton's method requires the derivative of this function, which is easy to find. Problem is, ...
5
votes
1answer
7k views

Solve a second order DEQ using Euler's method in MATLAB

I need to solve the equation below with Euler's method: $$y''+ \pi ye^{x/3}(2y' \sin(\pi x)+\pi y\cos (\pi x)) = \frac{y}{9}$$ for the initial conditions $y(0)=1$, $y'(0)=-1/3$ So I know I need ...
5
votes
3answers
4k views

Fitting an exponential function to data

I have a noisy data set (the grey line in the graph below) that corresponds roughly to $y=m(1-2^{-x/k})$ where m and k are unknown constants. How can I determine the best-fit value of m and k? I ...
4
votes
1answer
235 views

What algorithm is used in Matlab's pade function?

I try to find out for quite some time now, how Matlab implements the calculation of Padé Approximants using its symbolic pade function. (the code of is buried in a ...
4
votes
3answers
3k views

How to randomly construct a square full-ranked matrix with low determinant?

How to randomly construct a square (1000*1000) full-ranked matrix with low determinant? I have tried the following method, but it failed. In MATLAB, I just use: n=100; A=randi([0 1], n, n); while ...
3
votes
2answers
165 views

Minimize $\|AXBd -c \|^2$, enforcing $X$ to be a diagonal block matrix

Currently, I am minimizing the quadratic objective $\|\mathbf{A}\mathbf{X}\mathbf{B}\mathbf{d} -\mathbf{c} \|^2$ using CVX, as follows ...
3
votes
1answer
968 views

Matrix multiplication using Galois field

$$\begin{bmatrix}1 &1 &6\\4& 3& 2\\5 &2& 2\\5& 3& 4\\4& 2& 4\end{bmatrix}\begin{bmatrix}4\\5\\6\end{bmatrix} = \begin{bmatrix}3\\5\\4\\3\\2\end{bmatrix}. $$ I ...
3
votes
1answer
643 views

How to calculate discrepancy of a sequence

For $d\geq1$ let $I^d=[0,1)^d$ denote the $d$-dimensional half-open unit cube and consider a finite sequence $x_1,\ldots,x_N\in{I}^d$. For a subset $J\subset{I}$, let $A(J,N)$ denote the number of ...
2
votes
1answer
6k views

Solve Falkner Skan Numerically?

how would we go about solving the Falkner Skan equation numerically? The equation is $$f'''+ff''+\beta\left(1-f'^2\right)=0$$ $$f(0) = f'(0) = 0$$ $$f'(\infty) = 1$$ I tried using ODE45 to solve ...
2
votes
1answer
128 views

Higher order numerical PDE schemes near boundaries, implementation in MATLAB

Followup to my previous question. The first order scheme proved unstable for my pde: $$f_t + A y f_x - B x f_y =0$$ So I'm looking to implement a higher order scheme (using these tables). I was ...
2
votes
1answer
2k views

Matlab numerical integration involving Bessel functions returns NaN

I need to numerically compute integrals such as this (some parameters omitted for simplicity): $$ \int_{0}^{\infty} e^{-x^2} I_{0}(x) K_{0}(x) \mathrm{d}x $$ where $I_{0}$ and $K_{0}$ denote the ...
1
vote
1answer
3k views

QR decomposition with column pivoting, errror

I simply rewrote this algorithm http://faculty.nps.edu/borges/Teaching/MA3046/Matlab/qrlsdiary.html for QR ecomposition with columns pivoting to be applicable to a general matrix A (m, n). The ...