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.

MATLAB (Matrix Laboratory) is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks. MATLAB can be used when performing tasks such as signal processing and communications, image and video processing, computational finance, and computational biology. It is the foundation for a number of other tools, including Simulink and various toolboxes that extend its core capabilities.

In addition, MATLAB is a proprietary product of MathWorks. This means that, unlike other GNU GPL open source languages, both programmers and users must own a valid software license for running MATLAB code. There are several open source alternatives to MATLAB, in particular GNU Octave, which offers bidirectional syntactic compatibility with MATLAB, Scilab, SciPy, and Julia.

You could think about posting your question on Stack Overflow. They've got plenty of questions/answers already there.

Some informative links that show up quite often in answers:

User Amro has created a user-script for Matlab Syntax Highlighting for Stack Overflow. Use this link to install it.

3174 questions
54
votes
1 answer

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 possible. This is a research project and the goal…
49
votes
5 answers

How to generate random symmetric positive definite matrices using MATLAB?

Could anybody tell me how to generate random symmetric positive definite matrices using MATLAB?
32
votes
2 answers

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 Matlab. I think I have to discretize this equation…
23
votes
3 answers

Matlab wrong cube root

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.
Vaolter
  • 1,781
17
votes
2 answers

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$; and $ \mathbf{s} \leq \mathbf{x} \leq \mathbf t$…
Meekohi
  • 273
17
votes
2 answers

What is the dot product of complex vectors?

When I run dot(a,b) in MATLAB, I get a very different number than $\sum a_i \times b_i$, but is that not how one takes a dot product? For instance: A = [1+i 1-i -1+i -1-i]; B = [3-4i 6-2i 1+2i 4+3i]; dot(A,B) % => 1.0000 -…
Jellicle
  • 337
16
votes
3 answers

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 form. From Girko's Circular Law I'd expect the…
14
votes
3 answers

Orthogonal Projection onto the Unit Simplex

The Unit Simplex is defined by: $$ \mathcal{S} = \left\{ x \in \mathbb{{R}^{n}} \mid x \succeq 0, \, \boldsymbol{1}^{T} x = 1 \right\} $$ Orthogonal Projection onto the Unit Simplex is defined by: $$ \begin{alignat*}{3} \arg \min_{x} & \quad &…
Royi
  • 10,050
14
votes
2 answers

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 computation and the results by Yves Daoust here, the…
13
votes
2 answers

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 in matlab and I should consider multicolinearity…
Ramin
  • 421
13
votes
3 answers

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 describe this GIF animation? All comments are…
user117071
12
votes
2 answers

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 Internet, but did not find anything useful. Does anybody here have an idea where to find a…
11
votes
3 answers

Orthogonal Projection onto the $ {L}_{2} $ Unit Ball

On an article I'm reading, I find that: if $v$ is a vector, the projection of of $v$ on the unit ball is: $$p(v)=\frac{v}{\max\{1,\|v\|\}}$$ I know that a projection of a point $v$ into a space is the nearest point to $v$ inside the space..why the…
11
votes
2 answers

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)\,dt\quad(1) $$ where $$ f(t) =…
SBF
  • 36,568
11
votes
2 answers

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't seem to find out how to plot a piecewise function…
user90950
  • 227
1
2 3
99 100