Serving the Quantitative Finance Community

 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

plotting in matlab

August 2nd, 2005, 11:14 am

I’m trying to plot a graph in matlab but not being an expert on this I’m running into problems.I’ve written the following below and getting that error as shown below. Does anyone know how to proceed?EDU>>x=-10:1:10;EDU>> y=exp((9-1)/((x-1)*(x-9)));??? Error using ==> *Inner matrix dimensions must agree.
 
User avatar
Athletico
Posts: 14
Joined: January 7th, 2002, 4:17 pm

plotting in matlab

August 2nd, 2005, 1:01 pm

The * operator is matrix multiplication. x is a 1x21 vector, so matlab chokes on (x-1)*(x-9) b/c lhs and rhs are both 1x21.You either want to take the transpose of the rhs, (x'-9), which will give you a scalar, or (more likely since you say you are plotting) you want to use the dotted multiplication and division:y=exp((9-1)./((x-1).*(x-9)));Then you'll have to deal with division-by-zero ...
 
User avatar
ZmeiGorynych
Posts: 6
Joined: July 10th, 2005, 11:46 am

plotting in matlab

August 12th, 2005, 2:45 pm

As a matter of fact, I believe division by zero, and any NaN, is OK in plots - these points are simply omitted.
Last edited by ZmeiGorynych on August 11th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
henny
Posts: 0
Joined: January 28th, 2005, 7:04 pm

plotting in matlab

August 17th, 2005, 10:19 am

How does matlab recognize zero?
 
User avatar
ZmeiGorynych
Posts: 6
Joined: July 10th, 2005, 11:46 am

plotting in matlab

August 17th, 2005, 3:34 pm

Could you please rephrase the question? I am not sure I understand it.
 
User avatar
henny
Posts: 0
Joined: January 28th, 2005, 7:04 pm

plotting in matlab

August 17th, 2005, 3:42 pm

 
User avatar
ZmeiGorynych
Posts: 6
Joined: July 10th, 2005, 11:46 am

plotting in matlab

August 17th, 2005, 3:52 pm

Thanks. From my understanding of matlab, its variables are just doubles (or long doubles, or some such), with no symbolic structure like in Mathematica (you do get the maple kernel in a toolbox, but that's nowhere near the core of matlab). So if a variable is less than the smallest value that its type can hold, it is zero. This is one reason why engineers mostly dig matlab and a lot of mathematicians dig mathematica, I guess.
 
User avatar
henny
Posts: 0
Joined: January 28th, 2005, 7:04 pm

plotting in matlab

August 17th, 2005, 4:07 pm

I knew they all (maple. matlab. mathematika, etc) have to (no choice until one day...) use such ad hoc methods (as you described succintly). I just wanted to point out the big problem. Thanks to you too. As a side note, I heard maple and matlab are doing some work together. Do you know about this?