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.

3165 questions
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,711
8
votes
1 answer

What is the motivation behind naming identity matrix as "eye"?

Matlab, as well as some other PLs (e.g. Python's numpy package) use "eye" as a function name for creation of the identity matrix. Why is that so?
J Doe
  • 93
7
votes
1 answer

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 any similar function in Octave. Thanks!
skorek
  • 75
5
votes
4 answers

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 sentence "The program should output the $\infty$…
user136422
  • 247
  • 2
  • 4
  • 14
5
votes
1 answer

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.
Srijan
  • 12,518
  • 10
  • 73
  • 115
5
votes
3 answers

Why do $\frac{(e^{2x}-(e^x\cos x)^2)}{x^2}$ and $\left(\frac{e^x\sin x}{x}\right)^2$ give different numeric results?

I have two functions $$f(x)=\frac{(e^{2x}-(e^x\cos x)^2)}{x^2}$$ $$g(x)=\left(\frac{e^x\sin x}{x}\right)^2$$ which I have proved algebraically to be the same however doing computations with these functions for $x\to 0$ gives different results,…
BorisOZ
  • 53
4
votes
0 answers

Symbolic summation MATLAB

Can someone help me generate the following symbolic summation in MATLAB? I then want to differentiate the Jacobian matrix. $f(x) = \sum_{i=1}^{n} \sum_{j=1}^n (x_i (\Sigma x)_i - x_j (\Sigma x)_j)^2$ where $\Sigma - n \times n$ matrix and $(\Sigma…
Shahin
  • 41
4
votes
2 answers

Matrix of matrices in matlab

I need to build up the matrix of matrices. Say, for all $1\leq i,j\leq n$ I have to define a matrix $p_{ij}$ which will be a matrix $n\times n$. What I can do - it is to build up a matrix $P$ which is $n^2\times n^2$ - but for $n=20$ there is an…
SBF
  • 36,041
4
votes
1 answer

Can we make such matlab code so that every time we run the program it will return the same randomly generated matrices?

I want to compare efficiency of two iteration methods for computing inverse of a matrices. I want to test performance of these methods on some randomly generated matrices. I want to know can we make such matlab code so that every time we run the…
Srijan
  • 12,518
  • 10
  • 73
  • 115
4
votes
2 answers

MATLAB code for an array consisting of matrices

I want to write MATLAB code that includes an array consisting of all $2 \times 2$ square matrices whose elements are elements of $\Bbb{Z}_2= \{0,1\}$, e.g., $$ \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix},\quad \begin{pmatrix} 1 & 0 \\ 0 &…
Grazel
  • 501
  • 5
  • 17
4
votes
1 answer

Need matlab help related with the iteration method

I am reading an iteration method for computing the Moore- Penrose genralized inverse of a given matrix $A$, which is given as follows: $X_{k+1} = (1+\beta)X_{k} - \beta X_{k} A X_{k}$ where $X_{k}$, k = 0,1,... is a sequence of approximations for…
Srijan
  • 12,518
  • 10
  • 73
  • 115
4
votes
1 answer

How can I set values going up by powers of $2$ in matlab

I am writing a code which will need values of $\sin(x)$ for $x = 2^2, 2^3, 2^4, \dots, 2^{25}$ Being fairly new at matlab still, I am unsure how to do this in the most efficient manner. I know n=0:10 0 1 2 3 4 5 6 7 8 9 10 But putting in something…
elbarto
  • 3,356
3
votes
2 answers

LSQR with matlab

I am trying to use LSQR on matlab to solve a linear equations: $$ aX + bY = Z $$ so I form [a b][X Y]' = Z where a, b and Z are row vectors. I am testing it on simulation i.e controlled data. A = [a,b]; XY = lsqr(A,Z,1e-14,100); However, I cant…
3
votes
1 answer

Matlab: Using calculating with days.

My problem is the following: I have a start day. For example: 30 - Oct - 2010 And I know how many business days I need to count back. For example: 250 business days. Now I want to be able to calculate the start date. Start date = (30 - Oct - 2010) -…
user84112
  • 119
3
votes
3 answers

How to notate or write recurring decimals in Matlab?

I'm new on Matlab, and I have a question. Can I represent recurring decimals? For example I want to operate 216.6666666… by another number. I'll appreciate your answers.
Isai
  • 361
1
2 3
22 23