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
0
votes
2 answers

Generate a random integer between -2 and 1 inclusive

How can one generate a random integer between -2 and 1 inclusive? I know if I take rand*(b-a)+a I would get random real number between a and b Thanks
joke
  • 41
0
votes
1 answer

Matlab help with Newton's method

I'm doing something wrong. I don't know what. I get random numbers instead of anything that converges. So, this is supposed to converge to $\sqrt{x}$ ($\sqrt{3}$ here, which is approx. $1.732$). x = .5; b = 3; for i = 1:25 x = x -…
0
votes
2 answers

Help with Matlab rewriting subtraction as division

I have the function 1./(1-(x).^3)-1./(1+(x).^3) I need to rewrite this function so that it works well when I plot it on Matlab on the interval x=-0.00001:0.0000001:0.00001. So far, the best thing I have is $$\frac{(2/x^3)}{(1/x^6)-1},$$ but this has…
0
votes
1 answer

If normal distribution can be adapted to the set of data?

Using Matlab I need to generate a sample x of random numbers (n=30) from the normal distribution, using the command normrnd, and then check whether the normal distribution can be adapted to the sample. I used the Matlab function chi2gof which gives…
0
votes
1 answer

MatLab updating a recursive variable.

See the code x(1) = 0; k = 1; while x(k) <=6 x(k) = x(k) +2 k = k +1; end So I want the code to output x(1) = 2 x(2) = 4 x(3) = 6 Basically I want to write out a list of x(i)s, that gets updated during each iteration. But I am…
Lemon
  • 12,664
0
votes
2 answers

How to create an image from this function?

this is a newbie question. I would like to create an image that intensity obey to the following function g() : $$ g(x,y) = \begin{cases} -10, & x \in [-50, -10) \\ x, & x \in [-10, 10) \\ 10, & x \in [10, 50] \end{cases} $$ for $y = 0$ to…
user126407
0
votes
1 answer

Matlab, "tranpose(x)" not doing it right?

I just found this really weird thing in matlab, when I do x = [1 2 3]; tranpose(x)*x I don't get $14$ as an output, but I get a 3 x 3 matrix 1 2 3 2 4 6 3 6 9
Lemon
  • 12,664
0
votes
1 answer

Trapezoidal integration in matlab - code explanation

I have a simple matlab script for calculating an Integral using trapezoidal rule. The idea is calculate Fourier series, and it used for the Fourier coefficients. function [area] = recArea(func, xl, xr, N, n) if nargin < 5 n = 1; end …
Billie
  • 3,449
0
votes
1 answer

How to find coordinates of point in 3D given few points

How to find coordinates of point in 3D given coordinates of few(more than 3 non linear/noncoplaner) points and distance from desired point using MATLAB? suppose given five points are: [2.6643 1.4664 0.3019] [7.1360 1.4661 …
0
votes
2 answers

A basic MATLab question regarding iterations

Suppose I want to run a loop for integers $i = 2,2^2,2^3, \dots,2^n$ How would I do this? That is, suppose I want to evaluate some function f(i) through the increments $2, 2^2, 2^3$. I understand that for loops in MatLab can only take arithmetic…
Lemon
  • 12,664
0
votes
1 answer

How to solve linear equation using Matlab?

A= [1 2 3;3 4 5;5 6 7], B=[1;1;1]. I need to solve the equation $AX=B$. Here am using Matlab code like X=linsolve(A,B). But, using this a warning is occurred... "Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.…
0
votes
2 answers

How to write this simple matlab script to create a matrix from another matrix.

I have a matrix $A= \pmatrix{ 0 & 1/3 & 1/3 & 1/3 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1/2 & 1/2 \\ 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ }$ and I wish to add another matrix…
Nopas
  • 3
0
votes
1 answer

Writing a script for finding the largest and second largest eigenvectors of a symmetric matrix.

For a final project in my linear algebra intro, I have been tasked with writing a script that finds the largest and the second largest eigenvectors of a symmetric matrix in Matlab. For the best possible grade, it must include a function as well. …
Heath Huffman
  • 589
  • 3
  • 10
  • 18
0
votes
1 answer

Plot the x-axis and y-axis in Matlab

I am asked to plot the graph of a function in Matlab and I would like to add the x-axis and y-axis in the graph. But how can I achieve this?
Mary Star
  • 13,956
0
votes
2 answers

Writing a relatively simple MATLAB function

I'm new to MATLAB and I have been asked to write a MATLAB function whose input arguments are two integers $a$ and $b$; the output is the remainder of the integer division $a/b$ if $a>=b$ or of the integer division $b/a$ if $b>a$ Can someone help me…
Lewis
  • 3