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
5
votes
2answers
950 views

Finite Element Method for the 1d wave equation

I'm solving the 1D wave equation \begin{equation} \frac{\partial^2 \eta}{\partial t ^2} - \frac{\partial^2 \eta}{\partial x ^2} = 0 \end{equation} with boundary conditions \begin{equation} \frac{\...
5
votes
1answer
1k views

Matlab: need help with optimization

Minimize the following objective function over $(x_1,x_2)$ $$f (x_1, x_2) := \exp(x_1) \, (4 x_1^2 + 2 x_2^2 + 4 x_1 x_2 + 2 x_2 + 1) + b$$ subject to the constraints $$x_1^2 + x_2 = 1 -...
5
votes
1answer
7k views

Solve a second order DEQ using Euler's method in MATLAB

I need to solve the equation below with Euler's method: $$y''+ \pi ye^{x/3}(2y' \sin(\pi x)+\pi y\cos (\pi x)) = \frac{y}{9}$$ for the initial conditions $y(0)=1$, $y'(0)=-1/3$ So I know I need ...
5
votes
2answers
6k views

Visualizing elemental rotations using Euler angles in Matlab

I'd like to visualize elemental rotations using Z-Y-X convention in Matlab. If you'd like to follow me exactly, I'll be refering to a paper Quadrotor Dynamics and Control by Randal Beard. The base ...
5
votes
3answers
31k views

Implement a program in Matlab for LU decomposition with pivoting

I need to write a program to solve matrix equations Ax=b where A is an nxn matrix, and b is a vector with n entries using LU decomposition. Unfortunately I'm not allowed to use any prewritten codes in ...
4
votes
8answers
1k views

Best Math Plotting Software for Electrical Engineering

I am an electrical engineering undergrad. I would like to learn a math plotting software which would be helpful in visualizing topics in advanced calculus (my immediate need). It would also be helpful ...
4
votes
3answers
3k views

How to randomly construct a square full-ranked matrix with low determinant?

How to randomly construct a square (1000*1000) full-ranked matrix with low determinant? I have tried the following method, but it failed. In MATLAB, I just use: n=100; A=randi([0 1], n, n); while ...
4
votes
2answers
2k views

Inverse problem from pdes

A linear inverse problem is given by: $\ \mathbf{d}=\mathbf{A}\mathbf{m}+\mathbf{e}$ where d: observed data, A: theory operator, m: unknown model and e: error. To minimize the effect of the noise; ...
4
votes
3answers
328 views

Can't find all roots to function with fixed point method

I have a function $f(x) = x^2-8x-10\cos(2x)+15$ and I'm supposed to via Matlab find all roots for this function. I can see graphically that it has $4$ roots and I've written a matlab function to find ...
4
votes
4answers
1k views

Monte Carlo double integral over a non-rectangular region (Matlab)

I want to evaluated the following integral using Monte Carlo method: $$\int_{0}^{1}\int_{0}^{y}x^2y\ dxdy $$ What I tried using Matlab: ...
4
votes
3answers
2k views

Parametric equations and specifications of a triskelion (triple spiral)

I haven't been able to find the parametric equations and specifications to form a triskelion, a triple spiral (this is made of three interlocked couples of spirals). Using the parametric equation of ...
4
votes
3answers
22k views

How to plot a phase portrait for this system of differential equations?

I beg your help.. I'd like the phase portrait for this system: \begin{aligned} \frac{dx}{dt} &= x (7-x-2y) \\ \frac{dy}{dt} &= y (5-y-x) \end{aligned} I don't know how to use Mathematica/...
4
votes
2answers
136 views

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 \...
4
votes
2answers
20k views

write text using an equation

Well like the batman equations and equations for heart, I once saw a site that draws equation for whatever text you type....but now I can't find it. Does anybody know such a site? Also a general ...
4
votes
2answers
1k views

Conditional Number growth of Hilbert Matrix: Theoretical vs MatLab.

I need to investigate how the condition number of the Hilbert matrix grows with the size N. The Matlab command is: "cond(hilb(N),2)" Compute the condition number of the Hilbert matrices Hn ∈ R, N×N, ...
4
votes
1answer
6k views

What is the convergence order and asymptotic error constant for these results?

Define order of convergence and asymptotic error constant for a numerical method for equation solving. Two different methods have been used to solve the equations f(x)=0. Runs in Matlab give the ...
4
votes
3answers
1k views

Factorize Positive Definite Symmetric Matrix

Let's start from the assumption of disposal of a positive definite symmetric matrix of size $\ (N,N) $. For some reason I have to factorize this matrix: I am already aware of the ...
4
votes
3answers
3k views

MATLAB software for graph theory

I'm currently working on an undergraduate thesis that requires the use of graph theory(shortest path problem) in MATLAB. However, all the graph functions that I see in the MATLAB help bar do not make ...
4
votes
1answer
251 views

What algorithm is used in Matlab's pade function?

I try to find out for quite some time now, how Matlab implements the calculation of Padé Approximants using its symbolic pade function. (the code of is buried in a ...
4
votes
1answer
5k views

LU Decomposition vs. QR Decomposition for similar problems

Suppose I want to solve the 2D Poisson equation with Neumann boundary conditions. The solution is non-unique up to an additive constant. I have previously asked a related question here for the 1D ...
4
votes
2answers
2k views

making a sequence of numbers in octave and matlab

I know I can make a sequence of numbers in matlab / octave using x=1:1:5 and it will give me 1,2,3,4,5 but how can I get a ...
4
votes
1answer
4k views

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 ...
4
votes
2answers
210 views

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 ...
4
votes
1answer
860 views

Normality test vs. Fitting a Gaussian curve

I have a set of one-dimensional data, and I suspect that the data is normally distributed. Before embarking in a normality test, I decided to fit a Gaussian curve to the histogram of relative ...
4
votes
2answers
341 views

Finding analytical solutions for given equations

I have a system of 6 equations with 6 variables. The 6 variables are $t11, t12, t13, t21, t22, t23$ and the rest of the symbols in the equations are known symbols. I want to find all the possible ...
4
votes
1answer
188 views

If $X$ is symmetric, show $k(X^2)$ = $k(X)^2$

Suppose we have a symmetric invertible matrix $X$. How can I find $k(X^2)$ in terms of $k(X)$? Note that $k$ represents the condition number operation, that is $k(X) = \|X\|\,\|X^{-1}\|$. So, after ...
4
votes
1answer
114 views

How can I compute $\sum_{i=1}^n x_i \log(x_i)$ in a stable manner?

Given a vector in $\mathbb{R}^n$ I have an algorithm to compute $$\sum_{i=1}^n x_i \log(x_i)$$ However for my application the norm of $x$ must be 1, hence for big $n$ the components tend to be too ...
4
votes
3answers
927 views

Newton's Method: Found a case where it doesn't work. Why?

So I was looking to use Newton's Method to evaluate $x^3-2*x+2 = 0$. I noticed that I could plug in a negative number for $x_0$ and it worked but when I tried $x_0 = 0$ then my code started going ...
4
votes
1answer
980 views

Due to numerical inaccuracy, the solution of a boundary value problems becomes negative

I treat a toy example to get my point across. In reality I have to deal with a much more complex model. Let us consider a one dimensional boundary value problem using the bvp5c solver in Matlab. Two ...
4
votes
1answer
4k views

How to compute elliptic integrals in MATLAB

I need to calculate the complete elliptic integrals of the first and second kind , the incomplete elliptic integral of the first kind, and the incomplete elliptic integral of the second kind in MATLAB....
4
votes
2answers
2k views

Dot product over complex vectors: Conjugate first or second?

Does there exist a truly "standard" dot product over complex vectors? Wikipedia and Wolfram's MathWorld indicate directly or indirectly that the second argument is conjugated. Matlab's ...
4
votes
1answer
14k views

How can I write a tensor in MATLAB?

My project is about tensors and I must write the program in MATLAB. How can I write a tensor in MATLAB? Is there anybody to help me? Can you explain me what is the code for import a tensor? thanks for ...
4
votes
1answer
560 views

Matlab numerical triple integral involving quotient of two small quantities

Math people: I am trying to use Matlab's "triplequad" to numerically evaluate the triple integral $$\int_0^1 \int_0^{r_1} \int_{r_1-r_0}^{r_1+r_0} \left[\frac{Ov(r_0,r_1,t)^2}{(\frac{4}{3}\pi ...
4
votes
1answer
208 views

Problems with derivative of $\operatorname{sinc}$ when trying to interpolate in Matlab

Let $\psi\in C_c^{\infty}(\mathbb{R})$, with support away from zero and let $t\mapsto \phi(t)$ be a function of time satisfying the equality: $$\phi(t)=\int_0^t\psi(s)\,ds$$ and therefore: $$\psi(x)...
4
votes
1answer
487 views

fft of point wise product

I have a sequence a = [1 2 3 4 5 6 7 8], and a weighting ...
4
votes
1answer
904 views

Using Monte Carlo method to estimate the value of $\int_0^1\int_0^1e^{xy} \ dx \ dy$

Monte Carlo, estimate the value of $$\int_0^1\int_0^1e^{xy} \ dx \ dy.$$ I am using matlab to solve this problem. My code is the following: ...
4
votes
1answer
199 views

Solve the differential equation: $y''+(1-2x)y'+2x(e^{x^{2}}-1)y=xe^{x^{2}}$

I have an exercise of solving the equation above using MATLAB, with a hint to set $ v(x)=(y'+y)e^{-x^{2}} $. I tried to do with my hand and get the following: $ v'+2xy=x $, but I don't know what to do ...
4
votes
4answers
363 views

Numerical Integration of $\int_0^1 \log(x) dx$

Do you guys have any idea how to handle something like $\int_0^1 log(x) dx$ numerically in Matlab (I'm only interested in the real part btw)? I have used Quad, Quadl, "integral" etc all of them ...
4
votes
2answers
1k views

Binary Logistic Regression Model Processing

Thanks for showing interest and wanting to help out. My aim is to develop a model that - as accurately as possible - predicts how entities in a population will either cooperate or defect, as a % of ...
4
votes
1answer
1k views

How do I numerically calculate a function from its noisy gradient using “global integration”?

I have the model $\ s(x,y)=x^2+y^2, 0 \leq x \leq 1, 0 \leq y \leq 1 $. Instead of observing the model directly I am observing the derivatives of the model + some noise (e): $\ p(x,y)=s_x+e, q(x,y)=...
4
votes
1answer
6k views

MATLAB - ode45 “ODEFUN” format

Is someone able to explain to me exactly what the "odefun" called by the "ode45" ODE solver in MATLAB is supposed to do? My understanding is that you represent an n-order ODE as a system of n first-...
4
votes
2answers
798 views

Numerical Differentiation Matlab

I am trying to estimate the second derivative of $\sin(x)$ at $0.4$ for $h=10^{-k}, \ \ k=1, 2, ..., 20$ using: $$\frac{f(x+h)-2f(x)+f(x-h)}{h^2}\tag{1}$$ And then plot the error as a function of $h$...
4
votes
1answer
88 views

Did I do something wrong solving this PDE in MATLAB?

I have the following PDE problem on a practice exam: I have completed the problem using MATLAB to the best of my ability. Here is the code I used ...
4
votes
1answer
50 views

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

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

Plotting discrete time signals involving sumations in matlab.

Many of the examples I've encountered while looking for an answer are simple functions that do not involve summations. Suppose I have the following function; ...
4
votes
2answers
2k views

Using SVD in PCA for image compression

I found some help material and guided by it tried to implement PCA using SVD in MAtlab for image compression. I did it in this way: ...
4
votes
2answers
549 views

Graphing a function f(x,y) on a restricted set of values for (x,y)

I'm having a hard time with this certain problem. Suppose that $S=\{(x,y): x^2 + y^2\leq 4\}$ and define $f:S\rightarrow\mathbb{R}$ as $f(x,y)=-x-2y-2y^2+cos(x\pi /4)$. How can we produce a (3d) ...
4
votes
1answer
1k views

gradient flow programming (matlab)

Consider $$f(x,y)= x \ y \ e^{-x^2-y^2}$$ I need to find the gardient flow of f starting at the point (0,1) then (2,4). I know that this entails solving the follwing ODE $$\dot X(t)= - \nabla f(X(t))$...
4
votes
1answer
98 views

Is this a theorem in Statistics? If not, can anyone explain why this seems to be true?

It seems to me that the following is true: If $c$ is a random variable with probability $p(c)$ and cumulative probability $P(c)$, then the probability of $P(c)$ is constant. I have taken $N$ random ...
4
votes
1answer
946 views

How to solve an equation using Newton's method with and without backtracking?

Lets assume I have this equation: $$\log(e^x+e^{-x})=2x+5,\quad x \in (-50,50).$$ As always we have to pick a starting point to solve this by Newton's method, but how can i know for what initial ...