# 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.

130 questions
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/...
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 ...
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?
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 ...
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 ...
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 ...
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. ...
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'...
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 ...
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 ...
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 ...
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 ...
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 ...
818 views

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 ...
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 - ...
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 ...
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 ...
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 ...
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, -(\frac{\partial^2}{\partial y^2} + \frac{\partial^2}{\partial z^2})\Psi + \frac{\sinh^2(y) + \sinh^2(z)}{(\...
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$$...
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 ...
6k views

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

We know that the Taylor series expansion of $e^x$ is $$e^x = \sum\limits_{i=1}^{\infty}\frac{x^{i-1}}{(i-1)!}.$$ If I have to use this formula to evaluate $e^{-20}$, how ...
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: ...
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$...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...