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.

3075 questions
51
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…
43
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?
Srijan
  • 11,854
  • 9
  • 64
  • 108
25
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,661
  • 2
  • 16
  • 37
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…
15
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
  • 254
  • 3
  • 9
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

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
  • 401
  • 1
  • 4
  • 13
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) =…
Ilya
  • 34,060
  • 4
  • 69
  • 141
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
  • 4
  • 9
11
votes
1 answer

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 Carlo estimate of I ? I wrote the following to…
Chris
  • 387
  • 1
  • 5
  • 28
11
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…
Thomas
  • 4,213
  • 2
  • 19
  • 36
10
votes
1 answer

Solving a PDE with tricky boundary conditions

I'm reading this paper by Alexander Bloemendal currently and focusing on solving the following PDE numerically: \begin{align*} \frac {\partial F}{\partial x}+\frac {2}{\beta}\frac {\partial^{2} F}{\partial \omega^{2}}+\left(x-\omega^2\right)\frac…
10
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 -…
JellicleCat
  • 267
  • 1
  • 2
  • 8
10
votes
1 answer

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 two of the solvers (ode23s and ode23tb) produced…
1
2 3
99 100