Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

36
votes
4answers
29k views

How does the MATLAB backslash operator solve $Ax=b$ for square matrices?

I was comparing a few of my codes to "stock" MATLAB codes. I am surprised at the results. I ran a sample code (Sparse Matrix) ...
25
votes
4answers
8k views

Method for numerical integration of difficult oscillatory integral

I need to numerically evaluate the integral below: $$\int_0^\infty \mathrm{sinc}'(xr) r \sqrt{E(r)} dr$$ where $E(r) = r^4 (\lambda\sqrt{\kappa^2+r^2})^{-\nu-5/2} K_{-\nu-5/2}(\lambda\sqrt{\kappa^2+...
23
votes
12answers
18k views

Is it possible to use Octave to learn MATLAB programming?

I want to learn MATLAB programming so that I can conduct some researh/analysis on my own and also, so that I can study/modify some MATLAB scripts that I have found online etc. However, the problem is ...
15
votes
1answer
1k views

can I trust this numerical triple integral from Matlab?

Computational Science people: I originally posted this question at Math Stack Exchange and someone commented that I might get "much better" answers here: I am a novice at numerical methods and ...
12
votes
5answers
2k views

Repeatedly solving $\mathbf{A} \mathbf{x} = \mathbf{b}$ with same $\mathbf{A}$, different $\mathbf{b}$

I am using MATLAB to solve a problem that involves solving $\mathbf{A} \mathbf{x}=\mathbf{b}$ at every timestep, where $\mathbf{b}$ changes with time. Right now, I am accomplishing this using MATLAB'...
12
votes
2answers
3k views

Why does Matlab's integral outperform integrate.quad in Scipy?

I am experiencing some frustration over the way matlab handles numerical integration vs. Scipy. I observe the following differences in my test code below: Matlab's version runs on average 24 times ...
12
votes
3answers
3k views

Choice of step size using ODEs in matlab

Hey there and thanks for giving time to look at my question. This is a updated version of my question which I posted earlier in physics.stackexchange.com I'm currently studying a 2D exciton spinor ...
11
votes
4answers
1k views

good (free) software for producing publishable images?

I am producing 1d and 2d images using Matlab right now for comparison of accuracy against a given model. I need to compare my methods with the standard Gaussian .wfn model and I am going to do that by ...
11
votes
3answers
1k views

Least squares approximation question

I am taking a course on scientific computation, and we just went over least squares approximation. My question is specifically about approximating using polynomials. I understand that if you have n+1 ...
11
votes
2answers
3k views

What is the corresponding LAPACK function behind Matlab [Q,R,E]=qr(A)?

I currently trying to cheaply compute a good rank estimate for a matrix $A$. Therefore I compute a columnt pivoting QR decompostion using [Q,R,E]=qr(A) in ...
11
votes
1answer
1k views

How can I compute a basis for a matrix Lie algebra given a finite set of generators?

Given an arbitrary set of (numerical) square complex matrices $\mathcal{A}=\{A_1,A_2,\cdots,A_m\}$, I am interested in computing the real matrix Lie algebra generated by $\mathcal{A}$, call it $\...
10
votes
3answers
5k views

MATLAB matrix multiplication (the best computational approach)

I have to make a coordinates transformation between two reference systems (axes). For that, three matrices ($3\times3$) have to be multiplied due to some intermediate axes being used. I have thought ...
10
votes
4answers
14k views

Matlab : Is there a way to programatically safely halt code execution (like FORTRAN's stop)? [closed]

Like the title says, I want to be able to stop the code at a specific location and have it halt safely. I cannot find a command to do it like for example in FORTRAN there is the stop command.
10
votes
1answer
13k views

in matlab, what differences are between linsolve and mldivide?

in matlab, both linsolve and mldivide are used for solving a system of linear equations, in all of determined, overdetermined and underdetermined cases. Reading their documents, I was wondering what ...
10
votes
1answer
1k views

Optimal transport warping implementation in Matlab

I am implementing the paper "Optimal Mass Transport for Registration and Warping", my goal being to put it online as I just cannot find any eulerian mass transportation code online and this would be ...
9
votes
6answers
1k views

Soft Question: Where does Python fit into the picture?

So I've been debating whether or not I should bother learning Python. From speaking with my professors, Matlab seems to be the common language used in applied mathematics/computational science as far ...
9
votes
4answers
481 views

Hosting site for a small scientific library

For my research work I have been developing a small C++ library aimed at facilitating the communication between C++ computational codes and Octave/Matlab (when the latter is used for post-processing ...
9
votes
2answers
181 views

Numerical stability of higher order Zernike polynomials

I'm trying to calculate higher order (e.g., m=0, n=46) Zernike moments for some image. However, I'm running into a problem ...
9
votes
3answers
306 views

Can my project survive without Object Orientation?

I am writing a small MATLAB package which will solve a certain class numerical problems. There are 3 stages of the algorithm and the user has 5 choices for each stage. I have implemented the entire ...
9
votes
1answer
6k views

How to approximate the condition number of a large matrix?

How do I approximate the condition number of a large matrix $G$, if $G$ is a combination of Fourier transforms $F$ (non-uniform or uniform), finite differences $R$, and diagonal matrices $S$? The ...
9
votes
1answer
477 views

Matrix Balancing Algorithm

I have been writing a control system toolbox from scratch and purely in Python3 (shameless plug : harold ). From my past research, I have always complaints about ...
9
votes
1answer
739 views

Matlab Pde Toolbox: Plot solution on a line or on a submanifold

I'm using the Matlab pde toolbox to solve a certain elliptic equation in 2D. Solution is fine, although I do need to plot it along a given line, i.e. to cut a planar slice from the 3D mesh ...
9
votes
1answer
1k views

How to find Lyapunov exponent for coupled system

Answer gives a software for calculating conditional Lyapunov exponent (CLE) for coupled oscillators in chaos synchronization. However, it is hard to follow and there is no graphical output of the ...
8
votes
4answers
3k views

Incremental SVD implementation in MATLAB

Is there any library/toolbox which has implementation of incremental SVD in MATLAB. I have implemented this paper, it is fast but does not work well. I tried this but in this also error propagates ...
8
votes
3answers
2k views

Scientific Programming on Mac using Objective-C/Cocoa for MATLAB Users

I want to get started on scientific programming on the Mac using Objective-C. I am very familiar with MATLAB which makes it easy to store complex-valued waveform data in vectors and generating plots. ...
8
votes
2answers
568 views

How many Fourier magnitudes do I have to calculate before an FFT becomes more efficient than a DFT?

I need to compute only a small number of low frequency Fourier components of a complex 2-dimensional array. I'll be computing the same Fourier components over and over again as the input array changes....
8
votes
1answer
4k views

How to use Lanczos method to compute eigenvalues and eigenvectors

I have a sparse and symmetric matrix A(n x n). The method Lanczos tranforms matrix A into tridiagonal and symmetric matrix T and the Lanczos vectors in matrix V. From there how do I compute k ...
8
votes
3answers
1k views

Compute smallest eigenvectors of a matrix

It appears that matlab's eigs is giving me bad approximations of the smallest eigenvectors of a matrix. I assume I can use some slower methods which would also be ...
8
votes
1answer
177 views

How to recreate this result (from a book)?

The result I'm interested in is found within "Synchronization: A Universal Concept in Nonlinear Sciences" page $333$ figure $14.3$. The peculiar fragment is also provided at the end of this post. So ...
8
votes
3answers
4k views

Order of MATLAB FFT frequencies

This wikibook states that the output of MATLAB's FFT corresponds with the wavenumbers ordered as: $$k=\left\{0,1,...,\frac{n}{2},-\frac{n}{2}+1,-\frac{n}{2}+2,...,-...
8
votes
1answer
1k views

Automatically generating finite difference matrices for systems of PDEs

Suppose that you have a system of PDEs to solve. At least for simplicity, let's assume it's time independent, quasi-linear (linear in its derivatives) solved on a rectangular grid in (x,y) space, and ...
8
votes
1answer
8k views

Matlab solution for implicit finite difference heat equation with kinetic reactions

I am trying to model heat conduction within a wood cylinder using implicit finite difference methods. The general heat equation that I'm using for cylindrical and spherical shapes is: Where p is the ...
8
votes
0answers
418 views

Numerical implementation of the Dirichlet-to-Neumann map

I am solving the Dirichlet problem $$ \begin{cases} \Delta u = 0, \\ u|_{\partial D} = f, \end{cases} $$ in a $2d$ domain $D$ using the finite element method. What I want to get is the ...
8
votes
0answers
138 views

Tucker factorisation to compare multiple PCA decompositions?

This is an entry-level question for multiway matrix decompositions. I have a set/population $k$ of entities (here biological cells) for each of which I also have a number ($l$) of flavours of length $...
7
votes
5answers
3k views

Minimizing $\mathrm{trace}(S)+\mathrm{trace}(S^{-2})$ using CVX

In Matlab, I would like to minimize the function $$f(S)=\mathrm{trace}(S)+\mathrm{trace}(S^{-2})$$ where $S \in \mathcal{M}_{m,m}$ is symmetric and positive definite, which is definitely a convex ...
7
votes
4answers
30k views

How to code in Matlab: If an argument is empty, then default to “x” value?

I have a function with a number of arguments, but some of them are optional. 1.) If when the function is called, some are left empty, how do I code it so that it defaults to a specific value? 2.) ...
7
votes
4answers
192 views

In Matlab, how can I be consistent with units?

I am modeling some aerodynamics equations and am using meters / centimeters, kilograms, and seconds. I've heard that, "matlab doesn't know units". So, how can I make sure that it does? Just ...
7
votes
3answers
1k views

How to compute the rank of a large sparse matrix in MATLAB

I am interested in computing the ranks of fairly large, the largest being of magnitude $10^6$ x $10^6$, sparse matrices whose entires are all 0, 1, or -1. I have been trying to use Matlab to ...
7
votes
1answer
1k views

How do I vectorize this 4-D matrix operation in Matlab?

I need to do a large number of matrix operations in Matlab, but one of the matrices is 4-D and my normal instincts for correct vectorization are failing me. Right now I'm using a loop. Maybe somebody ...
7
votes
1answer
470 views

What is the numerical difference between abs(z)^2 and z x z*, where z is a complex number

I am doing research in electromagnetics (a branch of physics) and I deal with complex numbers in my computing tasks (I use MATLAB). Let's say $z$ is a complex number. To calculate the square of the ...
7
votes
2answers
2k views

How do I solve a boundary value ODE in MATLAB?

Specifically, ode15i. I have ode15i solving a system of 5 first order implicit odes in 5 variables with an initial condition (made consistent by decic). It's great for what I need, except I need to ...
7
votes
2answers
229 views

Caching mechanism

I've been having problems designing an effective caching mechanism. The mechanism is to be used as part of a project developing scientific software. The goal is to save computation time by loading ...
7
votes
3answers
212 views

Converting from planar polynomial domain to planar polygon

Let's assume we have a planar domain whose boundary can be described with a polynomial curve (like Bezier curves). Now assume that you want to produce a discretization of the boundary, i.e. you want ...
7
votes
2answers
186 views

Left and right eigenspaces of the product of Gramians

I solve the Lyapunov equations : $$ A W_C E^T + E W_C A^T + B B^T = 0 $$ $$ A^T W_O E^T + E W_O A + C^T C = 0 $$ to obtain $ W_C $ and $W_O$. My aim is to get the left and right eigenspaces of $W_C ...
7
votes
2answers
323 views

Numerical investigation of stability of motion (confinement)

I am trying to find the required specifications of a RF trap, in which a proton can be confined.(trap dimensions, voltage frequency and amplitude used, etc). I have to solve the equations of motion ...
7
votes
2answers
514 views

Numerical Green functions for a nonlinear wave equation

I am trying to put down some code to get numerically the solution of the following PDE: $$ \partial^2_t\phi-\partial^2_x\phi+\lambda\phi^3=\delta(x)\delta(t). $$ Of course, there are several ...
6
votes
2answers
385 views

Matrix multiplication accuracy Matlab vs Python

I am translating some Matlab code into Python and I having some problems regarding matrix multiplication accuracy. Assuming we have following data: ...
6
votes
5answers
2k views

What other method can be used to solve differential equations except ode functions in Matlab?

Recently I am taking advantage of the ode45, as well as ode23s, ode15s solvers in ...
6
votes
3answers
218 views

Nonlinear eigenvalue problem - MATLAB code

I'm trying to solve a nonlinear eigenvalue problem in MATLAB, still without success. It's a problem about graphene plasmonics. The nonlinear eigenvalue problem is given below: \begin{equation} \frac{...
6
votes
2answers
2k views

How can I generate half-normal variates in MATLAB?

I can find the random('normal', 0, 1, 10000,1) command in MATLAB but it generates half-normal variates. I would like to generate random half-normal variates. The ...