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
4
votes
2answers
1k views

Reconstructing space curves from its curvature and torsion

I have to write a program which gets two functions (curvature and torsion) and 3 vectors of the Frenet-Serret "frame" at the starting point - and I have to reconstruct the space curve from this given ...
4
votes
2answers
751 views

How to generate and use random trees?

I have the assignment to implement a random tree classifier in MATLAB. The lecture says: ...
4
votes
0answers
60 views

Solve issue with Matlab 2018b version

I was very successfully solving an equation numerically in Matlab R2014a with the following code ...
4
votes
1answer
83 views

Numerical methods for the matrix ODE $\dot L(t)=[L, \Pi_m(F\circ L)]$

Suppose $L$ is a lower-triangular matrix whose row sum is $0$. I want to numerically solve the following matrix ODE $$\dot L(t) = [L, \Pi_m (F \circ L)], \qquad L(0)=L_0$$ where $[\cdot \,,\cdot]$ ...
4
votes
0answers
50 views

Stiffness of a system of differential equations

For a university assignment I've been given three systems of differential equations: $$\bf{\dot{y}} = \begin{pmatrix}-2 & 1\\ 1 & -2\end{pmatrix} * \bf{y} + \begin{pmatrix}2 * \sin(t)\\ 2*(\...
4
votes
0answers
92 views

Pseudo-inverse with minimal number of non-zero entries

I'm looking for a way to compute the pseudo-inverse of a matrix (not the Moore-Penrose, but any other) with the minimal number of non-zero entries (maximum number of zero entries). In MATLAB, the the ...
4
votes
0answers
5k views

Checking positive semidefiniteness in MATLAB

Let $\mathbf{A}$ be a $n\times n$ matrix. I want to check in MATLAB if it is PSD or not. Which tests, in MATLAB, should I do for this purpose? I know that if $\mathbf{A}$ is PSD then following holds ...
4
votes
0answers
51 views

Estimating the parameters of stochastic asset price models using Matlab

I am simulating asset prices using different existing stochastic models, as well as my own proposed stochastic models. I would like to estimate the parameters of each model using the historical spot ...
4
votes
1answer
435 views

taking partial derivative via fourier transform using matlab

For a task for university, I need to calculate in matlab a partial derivative using the 2D Fourier transform. Using equation (13) on pg 3 in http://www2.ph.ed.ac.uk/~wjh/teaching/Fourier/documents/...
4
votes
0answers
183 views

Matlab's dwt2 in publication quality notation?

I used Matlab's dwt2in my algorithm, what notation have you folks seen that describes the 4 resulting wavelets? How do I express ...
4
votes
0answers
702 views

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)^...
4
votes
0answers
948 views

How to avoid numerical overflow while computing a sum of products?

Suppose we have $N$ vectors $\vec{x}_1, \vec{x}_2,\dots,\vec{x}_N$. $\vec{x}_i$ is a $M$-dimensional vector: $\vec{x}_i = \left[ x_{i1}\;\; x_{i2}\;\; \dots \;\;x_{iM}\right]^T$ with all $x_{ij}>0$....
3
votes
5answers
2k views

Does rotation of a rectangle keep it rectangular?

If I rotate a rectangle by 45°, does it stay rectangular or become something else? I mean do 90° angles stay 90°? I am asking this question because I have some results where the rotated rectangle ...
3
votes
2answers
4k views

Fitting a 3D line to a 3D line point cloud

I want to fit a 3D line to a 3D line point cloud using numerical optimization. Currently, I'm using Steepest Descent and the error function is a function of $\alpha$, $\beta$, $\gamma$; that is, 3 ...
3
votes
3answers
20k views

Matlab Speech Recognition - Mel-Frequency Cepstrum Coefficient (MFCC)

I'm following this Matlab Speech recognition tutorial. I'm stuck on page 5 on the term/concept of MFCC feature vectors. I'm unable to grasp the concept of what an MFCC is.. a matlab function, ...
3
votes
2answers
1k views

How to approximate $\sin(x)$ using Padé approximation?

I need to write a function for $\sin(x)$ using Padé approximation. I found here a formula, but I don't know how to achive this. Thanks in advance.
3
votes
1answer
99 views

Inviscid Burgers equation with trapezoidal boundary data

Im trying to solve $v_t + vv_x = 0$ subject to $$ v(x,0) = \begin{cases} 0, & 0 \leq x \leq 1 \\ x -1, & 1 \leq x < 2 \\ 1, & 2 \leq x \leq 3 \\ 4 - x, & 3 \leq x \leq 4 \\ 0, &...
3
votes
2answers
1k views

determinant of a very large matrix in MATLAB

I have a very large random matrix which its elements are either $0$ or $1$ randomly. The size of the matrix is $5000$, however when I want to calculate the determinant of the matrix, it is either $Inf$...
3
votes
1answer
6k views

Projection matrix onto null space

I have a matrix $H$ and I want to find the projection matrix onto null space. How can I do this?
3
votes
1answer
19k views

Compute Angle Between Quaternions (in Matlab)

I am working on a project where I have many quaternion attitude vectors, and I want to find the 'precision' of these quaternions with respect to each-other. Without being an expert in this type of ...
3
votes
1answer
6k views

Phase shift of two sine curves

How do I determine phase shift of two sine curves (discrete time sampled sine curves) in Matlab. Currently, I have the FFT of these two sine curves, the phase shift is just the delay in time, which ...
3
votes
2answers
3k views

Simulating Diffusion/Wiener Process with Random Walk

I hope this is the right section for this kind of questions. I am trying to simulate, with MATLAB, a diffusion model starting from a Random Walk. I am using a Random Walk with information increment ...
3
votes
3answers
85 views

Changing [2,4] into [0,1,0,0,0,1] in Matlab

Good day, I apologize for the very vague title, I didn't really know how to formulate what I want. However, I can explain what I mean: I have a vector v1: ...
3
votes
2answers
5k views

Finding D matrix in LDU in matlab

I have been searching the web for nearly 3 hours about a MatLab function that can take matrix A and give me back L, D, and U. ...
3
votes
2answers
2k views

Matlab code for computing index of matrix

I need help to make Matlab code for computing index of matrix. The index of matrix $A$ is the least non negative integer $k$ such that $\operatorname{rank}(A^{k+1}) = \operatorname{rank}(A^k)$. ...
3
votes
2answers
28k views

Matrix is singular to working precision

I have a problem while evaluating inverse using inv in MATLAB. My matrix looks like this: ...
3
votes
2answers
2k views

Multivariate normal value standardization

I am wonder how to standardize multivariate normal value. Normal standard multivariate distribution of $q$ variables is $z\sim N_q(0,I_q)$. I have found that $a+Bz\sim N_q(Ba,BB^T)$ and based on this ...
3
votes
1answer
348 views

Runge Kutta stability

I am facing a problem solving a ODE with a Runge-Kutta 4th order method: The expression in order to solve is : \begin{equation} Ay^{''}+By^{'}+Cy= Cu \end{equation} \begin{equation} y =OUTPUT \end{...
3
votes
1answer
11k views

Eigenvectors in Matlab/Octave, function “eig()”, why are the eigenvectors output like that? [closed]

You can calculate eigenvectors of a matrix with eig() function like this: [eigenvectors, eigenvalues] = eig (matrix) But I can't manage to understand why the eigenvector output is in some kind of ...
3
votes
4answers
20k views

Understanding Fourier transform example in Matlab

I'm studying about Fourier series and transform and I get confused with the following Matlab example of Fourier transformation: ...
3
votes
2answers
6k views

Which optimization algorithm converges faster?

everyone. I'm having a large scale unconstrained optimization problem. If I treat the unconstrained problem as a constrained problem with infinity constraints, I should be able to use both the ...
3
votes
1answer
1k views

A problem for Matlab solver

I can numercally solve a system of two ODEs for x and p: dy1 = -y1 + y2 dy2 = -1 + y2 with the following Matlab code: ...
3
votes
1answer
960 views

Efficient multiplication of super-size matrices in matlab

I don't have enough memory to simply create diagonal matrix D x D, getting an 'out of memory' error. Instead of performing M x D x D operations in the first multiplication, I do M x D operations, but ...
3
votes
2answers
76 views

Calculating value of $\text{sinc}(x)$, WolframAlpha and MATLAB give two different answers.

I need to evaluate the following: $$\frac{2}{3}\text{sinc}\bigg(\frac{2\pi}{3}(n-4)\bigg)-\frac{1}{3}\text{sinc}\bigg(\frac{\pi}{3}(n-4)\bigg)$$ for $n=[0,...,8]$ I don't have the sinc function in ...
3
votes
2answers
1k views

Lax-Wendroff method for linear advection - Matlab code

$$ {\bf u}^{n+1} = {\bf u}^{n} - \frac{\Delta t}{2 \Delta x} {\bf c}.^*({\bf D}_{\bf x}{\bf u}^n) + \frac{\Delta t^2}{2 \Delta x^2} {\bf c}^2.^*({\bf D}_{\bf x x}{\bf u}^n) + \frac{\Delta t^2}{8 \...
3
votes
2answers
685 views

Getting complex solutions with MATLAB's ode45

I'm trying to solve the ODE below using Matlab's ode45: $$\frac{dy}{dx}=\sqrt{A\cdot \sin(y) + B\cdot \cos(y)}$$ where $0\le x \le 1$. The Matlab code is: ...
3
votes
3answers
2k views

Solving linear system with rank-deficient matrix in MATLAB

I want to perform quartic regression on following data: ...
3
votes
2answers
349 views

In MATLAB, $\pi$ value is given as 355/113. why?

$\pi$ is an irrational number. MATLAB shows it equal to 355/113 in fractional format. Is there no better fractional representation than 355/113 within the limits of the finite precision the ...
3
votes
3answers
1k views

How to compute the incomplete Gamma function with an negetive parameter in MATLAB?

I need to compute the upper incomplete gamma function $$\Gamma(-0.5,0.5r)$$ But in MATLAB, the upper incomplete Gamma function "gammainc" is defined as $$\Gamma\left(\alpha ; x\right) = \dfrac{1}{\...
3
votes
1answer
3k views

Roll PID Control for quadcopter

I'm trying to implement with simulink a PD controller for my quadcopter. I use a simplified model, and for the roll case I have $ I_x * \phi = L $, where L is the roll torque. So, the transfer ...
3
votes
2answers
949 views

MATLAB Eigenvalues

So I am trying to get matlab to output the correct eigenvalue/eigenvector of a matrix. The matrix is: \begin{array}{ccc} 0 & 1 \\ -3 & -4 \end{array} The eigenvalues are: $\lambda_1 = -1, \...
3
votes
5answers
2k views

Round a set to the nearest values in another set (2D), faster algorithm with Matlab

Given a set of numbers, like A={{1,2.5,3}, {4.2,7,10}}; and another set of numbers, like B={1,2,3,4,5}; Is there a fast ...
3
votes
3answers
15k views

Normalizing a Gaussian Distribution

Assuming a Gaussian distribution with mean of zero and standard deviation of one, I would like to normalize this for an arbitrary mean and standard deviation. I know you're supposed to add the mean ...
3
votes
3answers
2k views

Why is MATLAB giving me these weird eigenvectors?

I am doing a problem which involves finding the eigenvalues and eigenvectors of the matrix $$ M=\begin{bmatrix} 0 & 1/2 & 1/2 \\ 1/2 & 0 & 1/2 \\ 1/2 & 1/2 & 0 \end{bmatrix}$$ ...
3
votes
1answer
5k views

Can't understand a simple wave equation matlab code

I'm trying to figure out how to draw a wave equation progress in a 2D graph with Matlab. I found this piece of code which effectively draw a 2D wave placing a droplet in the middle of the graph (I ...
3
votes
2answers
365 views

Finding nearest left and right root using Newton-Raphson

The following is a problem in a Numerical Methods class. Consider the following function: $$f(x) = x^3 - \frac{31}{10}x^2+\frac{1}{10}x+\frac{21}{5}$$ Implement a method that will allow ...
3
votes
2answers
165 views

Minimize $\|AXBd -c \|^2$, enforcing $X$ to be a diagonal block matrix

Currently, I am minimizing the quadratic objective $\|\mathbf{A}\mathbf{X}\mathbf{B}\mathbf{d} -\mathbf{c} \|^2$ using CVX, as follows ...
3
votes
2answers
135 views

Why does using the identity $e^x=1/e^{-x}$ work better in evaluating negative numbers in the finite taylor series expansion of $e^(x)$

Was in class where we look at both and notice that there is a difference in the error, but we didn't go into why. The other method used the taylor expansion $$e^x=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+...$...
3
votes
1answer
1k views

Least-squares problem with quadratic equality constraint

I want to find the solution of a Lagrange equation whose inputs are matrices. First I have the equation Ax=0. By decomposing $A$ into $A_3$ (columns 9 to 11 of A), $A_9$ (the rest of the columns), ...
3
votes
2answers
92 views

What is the chance of a sample in white noise to be a local extremum?

I draw a long sequence of values from a uniform or normal distribution. Observing the resulting sequence, what is the chance of any point in the sequence (aside from the first and last where it is not ...