Questions tagged [matlab]

Questions about the numerical programming language MATLAB.

MATLAB (MATrix LABoratory) is a commercial software (MathWorks; originally developed at the University of New Mexico) that offers a high-level programming language with particular emphasis on vector and matrix based operations and plotting capabilities in an interactive development environment.

Questions tagged should be concerned with the mathematical capabilities of Matlab (e.g., solving linear systems, using eigs with anonymous functions, choosing functions or toolboxes for a certain scientific problem).

Questions about the programming language of MATLAB (e.g., vectorizing loops, manipulating arrays) belong to Stack Overflow; questions about the development environment (including manipulating plots) should be posted at MATLAB Central.

830 questions
15
votes
1 answer

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 Matlab. I am attempting to evaluate the following sum…
Stefan Smith
  • 515
  • 3
  • 13
10
votes
4 answers

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

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.
9
votes
3 answers

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 problem using $\approx 20$ functions and 3 switch…
MATLABOOP
  • 93
  • 2
7
votes
4 answers

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.) What if of 5 arguments, 3 are optional, how can the…
TheRealFakeNews
  • 593
  • 1
  • 4
  • 16
6
votes
4 answers

Ordering of Eigenvalues and Eigenvectors in MATLAB

The following MATLAB function produces the Eigenvalues and Eigenvectors of matrix X. [V,D] = eig(X) produces a diagonal matrix D of eigenvalues and a full matrix V whose columns are the corresponding eigenvectors so that X*V = V*D. My questions…
eualin
  • 211
  • 2
  • 3
  • 7
6
votes
2 answers

Is there any numerical reason for not using repeated multiplication instead of integer powers?

I recently discovered that, in MATLAB 2013b at least, it is significantly faster to do repeated multiplication rather than integer powers. That is, tic;test4p = a.^4;toc is much slower than tic;test4m = a.*a.*a.*a;toc See…
WalkingRandomly
  • 263
  • 1
  • 7
5
votes
2 answers

Fast computation on 2D rectangular cartesian grid using matlab

I have a density function $f(x,y)$ on a rectangular domain $[0,1] \times [0,1]$ My domain is divided into cells of length $[0,h] \times [0,h]$, and I want to compute mass of each cell. I am going through each cell by using two for-loops, but then…
user74261
  • 151
  • 3
4
votes
2 answers

setting a condition on MATLAB ode45 output

I want to solve a system of differential equations using ode45 , for (many) parameters in MATLAB to investigate the behavior of solutions with coefficients of the equation .I want to find the parameters for which the solution absolute value doesn't…
Mostafa
  • 249
  • 2
  • 11
4
votes
1 answer

Creating spheres In Matlab that change surface color depending data

I am trying to create a series of randomly distributed spheres in Matlab, three will be three sub-sets. I would like each subset to have a different color. I am using a structure because each sphere will also have different properties associated…
Cerberus
  • 153
  • 3
4
votes
2 answers

How to find all roots of equation in Matlab?

How to find all roots of an equation in Matlab? I tried and it gave me just one of the roots. For example: my equation is $F(x)=0$ where F(x) = (cos(7*x)).*exp(-2*x.^2).*(1-2*(x.^2))
majid
  • 41
  • 1
  • 1
  • 2
3
votes
1 answer

Export mesh and solution from pdetool

I need to run the pdetool analysis several times for different values of pde coefficients. Repeating this procedure for different meshes is not convenient using the pdetool GUI. Is there a way to automate the whole process via a .m file? The .m…
user1234
  • 167
  • 2
  • 7
3
votes
2 answers

Handling function inputs in Matlab

Say I have a function function u = somefxn(f,n) where f is some function, say f = pi^2*sin(pi*x), and n is the number of discretizations (let n = 1024) on the interval $[0,1]$. In my code I've written h = 1/n %n = 1024 x = 0:h:1…
TheRealFakeNews
  • 593
  • 1
  • 4
  • 16
3
votes
3 answers

Unable to calculate binomial coefficients correctly in matlab

I tried to compute the value of the following expression in Matlab: $$ 2^l\sum_{i=0}^{n-1}{N\choose i}\varepsilon^i(1-\varepsilon)^{N-i} $$ where $N=16272$, $n=499$, $l=107$, $\varepsilon=0.02$. I tried to use nchoosek(n, k) but I got warnings of …
Alex Cage
  • 31
  • 1
3
votes
1 answer

Anonymous function in MATLAB

I want to write the following anonymous function in MATLAB. I have a piecewise function. I want to turn this into a single expression. How can this be accomplished in MATLAB ? $$f(x,t) = \begin{cases} 20e^{-4x^2} & \text{if $0 \leq t \leq T/2,$}…
user36184
3
votes
1 answer

Understanding wall time jitter in MATLAB computations

I am studying a research paper on iterative methods to compute generalized inverses of an arbitrary matrix $A$. I am studying the following iterative method: $$Y_{k+1} = Y_{k} + Y_{k}(I - AY_{k}),$$ given an initial approximation $Y_{0}$. I am…
Srijan
  • 365
  • 1
  • 10
1
2 3 4 5