The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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.

Filter by
Sorted by
Tagged with
49
votes
1answer
21k views

Is Sage on the same level as Mathematica or Matlab for graph theory and graph visualization?

The context: I'm going to start working on a project that involves running predefined algorithms (and defining my own) for very big graphs (thousands of nodes). Visualization would also be welcome if ...
32
votes
5answers
54k 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?
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.
18
votes
2answers
18k 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 ...
15
votes
3answers
1k views

A hole in the distribution of eigenvalues - is this real?

Plot the eigenvalues of many $n\times n$ real matrices in the complex plane, where the matrices are taken from a some distribution. For $n>7$, you can start to see a hole at the origin starting to ...
12
votes
3answers
799 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
2answers
47k 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'...
11
votes
2answers
2k 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 - ...
11
votes
2answers
4k views

Numerical solution of an integral equation

I have problems with a solution of an integral equation in MATLAB: all conditions are double-checked, but the answer is incorrect. Let me state the equation: $$ x(s) = g(s)+\int\limits_0^1x(t)f(t-s)\,...
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 ...
10
votes
2answers
6k views

Are “constrained linear least squares” and “quadratic programming” the same thing?

A Quadratic Programming problem is to minimize: $f(\mathbf{x}) = \tfrac{1}{2} \mathbf{x}^T Q\mathbf{x} + \mathbf{c}^T \mathbf{x}$ subject to $A\mathbf{x} \leq \mathbf b$; $C\mathbf{x} = \mathbf d$; ...
9
votes
2answers
23k views

To invert a Matrix, Condition number should be less than what?

I see that there is a matlab tag in this site, so I ask my question here and not in stackoverflow although it is also related to programming in matlab. I am going to invert a positive definite matrix ...
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 ...
9
votes
5answers
9k views

To “subtract” two matrices with different dimensions in Octave (Matlab)

I have matrix and need to subtract another matrix element by element on each row. Something like this: $$ \begin{pmatrix} x_{1} & x_{2}\\ x_{3} & x_{4}\\ \vdots & \vdots\\ x_{n-1} &...
9
votes
1answer
1k views

Fast algorithm for approximating Eigenvalue distribution of large sparse matrix

I am interested in the eigenvalue distribution of a huge $2^{16}$x$2^{16}$ Hermitian sparse matrix with spectrum contained in $[-1,1]$. That is I don't need to know all eigenvalues exactly, but rather ...
8
votes
2answers
13k 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 ...
8
votes
3answers
1k views

Matlab code to compute the smallest nonzero singular value of the matrix without using SVD

I want to compute the smallest nonzero singular value of the matrix A, which is defined as follows. Let $B = rand(500, 250)$, $A = B*B^t$, where $t$ denotes the transpose of the matrix. I found ...
8
votes
3answers
5k views

How can I write an SDE in Matlab?

My professor would like me to solve a system similar to the following: $$ dx_i=[f_i(x_1,x_2,...x_n)]dt + g_ix_idW_i$$ Where $g_i$ are positive constants that measure the amplitude of the random ...
8
votes
3answers
693 views

is there a name for this function (parity of a finite sequence)?

Variants of this question have been crossposted to Stack Overflow and Computational Science Stack Exchange. Additional answers may be found at these other sites. Math people: In an attempt to solve ...
8
votes
0answers
416 views

Fixed point iteration to find root of Arctan

I am trying to find the root of $f(x)=\arctan(x)$ by using successive iteration. There are some conditions to apply this in successive iteration . 1) The function has to be continuous. 2) $\sup|f'(...
7
votes
1answer
13k 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 ...
7
votes
2answers
156 views

How to solve this equation (may be with least squares)?

I have the optimization problem $$\arg\min_{a,b} \sum_{i,j} \left( \left| X(i,j)-aY(i,j)\right|-b \right)^2$$ Where $X$ and $Y$ are known. But there is a modulus inside. I need to estimate $a$ and $...
7
votes
0answers
270 views

Two Matlab ODE solvers, two different results

I am solving a system of ODEs using Matlab. One particular set of parameters caused the solver to fail, so I worked my way through the different solvers Matlab provides. I was surprised to find that ...
7
votes
0answers
458 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
3answers
248 views

Using collocation method to solve a nonlinear boundary value ODE

I have the following ODE $$ u'' = -(1 + e^u), \quad u(0)=0,\quad u(1)=1$$ I want the divide the interval $[0,1]$ into $n-1$ equal subintervals each with length $h=1/(n-1)$ and we take approximate ...
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: ...
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, ...
6
votes
3answers
7k views

Bayesian Network for dummies

I know the Bayes Theorem but I've never heard nor used Bayesian Networks. Now I'm told to use Bayesian networks to estimate a dysfunction probability in a noisy signal with Matlab Can someone please ...
6
votes
2answers
8k views

Solving $Ax=b$ under $L_1$ $|Ax-b|$ minimization

I would like to solve a linear system $Ax = b$ under the $L_1$ norm constraint $\min(|Ax-b|)$. All that I can find about $L_1$ minimization is a way to minimize $|x|_1$ subject to $Ax=b$. I wanted to ...
6
votes
3answers
8k views

Kendall tau calculation

Can someone explain how the Kendall tau works? I can't seem to find a good explaination/tutorial/example. I've been running corr(x,y,'kendall') from Matlab's ...
6
votes
3answers
293 views

Suggestions for a project in matlab [closed]

I'm doing a project on numerical integration in Matlab and I'm looking for some nice things to program. So far, I programmed: Trapezium rule Simpson rule Double integral over a rectangle Estimating $...
6
votes
2answers
2k views

Image Reconstruction:Phase vs. Magnitude

Figure 1.(c) shows the Test image reconstructed from MAGNITUDE spectrum only. We can say that the intensity values of LOW frequency pixels are comparatively more than HIGH frequency pixels. $$ f(x,y)=...
5
votes
4answers
77k views

Creating a Tridiagonal matrix in matlab

How can I create a tridiagonal matrix that I can use for Crout factorization? And, I don't have any codes on how to create one since I am new to matlab. Ok, please help me understand what does the ...
5
votes
4answers
811 views

Why can you not omit the '*' sign for multiplication in Sage, Matlab, and other mathematical software? [closed]

Question I have some experience with Sage and Matlab. Both mathematical software packages require you to have the '*' sign when multiplying symbolic variables with integers. For example, in Matlab ...
5
votes
2answers
6k views

Time complexity of quadratic programming

I am using the Matlab built-in quadprog to solve a quadratic program with linear constraints. I vaguely recalled from school that the time complexity of quadratic programming should be $O(n^3)$, and I ...
5
votes
1answer
295 views

Implementing numerical scheme for 2D heat equation in MATLAB

We have 2D heat equation of the form $$ v_t = \frac{1}{2-x^2-y^2} (v_{xx}+v_{yy}), \; \; \; \; (x,y) \in (-1/2,1/2) \times (-1/2,1/2) $$ We can solve this equation for example using separation of ...
5
votes
2answers
2k views

In a linear program, how to add a conditional bound to x?

I am working with a standard linear program: $$\text{min}\:\:f'x$$ $$s.t.\:\:Ax = b$$ $$x ≥ 0$$ Goal: I want to enforce all nonzero solutions $x_i\in$ x to be greater than or equal to a certain ...
5
votes
2answers
1k views

Incomplete beta function in MATLAB

Mathematica is capable of evaluating the incomplete beta function $$ \mathrm{Beta}[z,a,b] = \int_0^z u^{a-1}\left(1-u\right)^{b-1}\,du $$ even when the argument $z$ is negative. MATLAB's function <...
5
votes
1answer
5k views

LU Decomposition vs. QR Decomposition for similar problems

Suppose I want to solve the 2D Poisson equation with Neumann boundary conditions. The solution is non-unique up to an additive constant. I have previously asked a related question here for the 1D ...
5
votes
1answer
298 views

Generating $n\times n$ random matrix with rank $n/2$ using matlab

Can we generate $n \times n$ random matrix having any desired rank? I have to generate a $n\times n$ random matrix having rank $n/2$. Thanks for your time and help.
5
votes
1answer
195 views

What is the difficulty when calculating this integral?

"What is the difficulty when calculating the integral $$\int_0^∞ \frac{6}{x^7+2x+1} dx $$ ? Solve the integral with matlab's quad." Sorry for my bad formatting, I'm just learning this formatting. ...
5
votes
1answer
7k views

How to generate orthogonal matrix in Octave?

How to generate an orthogonal matrix in Octave? I saw something like that gallery('orthog',n,k) in matlab, but I can't find ...
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 ...
5
votes
1answer
190 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$...
5
votes
1answer
582 views

Principal component analysis (PCA) results in sinusoids, what is the underlying cause?

Background I'm analysing a data set of $M$ flow measurements (volume per time). The flows go from zero mL/s gradually to higher values and back to zero again, thus: their shapes ideally look like a ...
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. ...
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$$...
5
votes
1answer
3k views

arc length parameterization of planar curve in Matlab

Let $\gamma (t)$ be a planar curve parameterized by time $t$. For fun, let it be a limacon. In Matlab $\gamma (t)$ looks like this. ...
5
votes
2answers
2k views

Dot product over complex vectors: Conjugate first or second?

Does there exist a truly "standard" dot product over complex vectors? Wikipedia and Wolfram's MathWorld indicate directly or indirectly that the second argument is conjugated. Matlab's ...