Thread Subject: Simple request; plotting problem

Subject: Simple request; plotting problem

From: chip

Date: 26 Nov, 2009 08:06:53

Message: 1 of 3

Hi there. I have a problem with the version of Matlab which I'm using. whenever I try to plot values obtained from the code below, the graphs I generate are erroneous. On newer versions on Matlab, the plotting works fine, but the one I'm stuck with now makes no sense. Here's the code:

----

l = -0.0150 - 0.1726i;

r = 1;

k = 0.02;

A = 3;

Ms0 = 0.06;

Mh0 = 100

Ms = Ms0;

Mh = Mh0*1.1;

a = 0.5;

ms = 0;

mh = 0;

for t = 1:500;

ms = Ms - Ms0 + dMsdt;

mh = Mh - Mh0 + dMhdt;

dMsdt = -r*Ms+k*a*Ms*Mh;

dMhdt = -a*Ms*Mh+A;

a = real(-(dMhdt-A)/(Ms*Mh));

Ms = Ms0 + ms*exp(l);

Mh = Mh0 + mh*exp(l);

Msf(t) = Ms;

Mhf(t) = Mh;

end;

----

And I need a plot of Ms and a plot of Mh both with respect to t.

Here's an image of what I'm getting: http://img20.imageshack.us/img20/8797/mhmswrong.jpg
But I know for a fact that the code is correct and it should look like an ever dampening sinusoidal wave. Basically if someone could kindly plot the two graphs for me and then upload the image to imageshack or somewhere, i would really appreciate it! thanks!

Subject: Simple request; plotting problem

From: dpb

Date: 26 Nov, 2009 13:32:55

Message: 2 of 3

chip wrote:
> But I know for a fact that the code is correct and it should look
> like an ever dampening sinusoidal wave. Basically if someone could
> kindly plot the two graphs for me and then upload the image to
> imageshack or somewhere, i would really appreciate it! thanks!

Well, I get from your code as posted--

??? Undefined function or variable 'dMsdt'.

Error in ==> C:\matlabR12\work\CHIP.M
On line 13 ==> ms = Ms - Ms0 + dMsdt;

If I presume those were to be zero-initialized, the result for

 >> max(Mhf)
ans =
      -Inf + NaNi
 >> max(Msf)
ans =
       Inf + NaNi
 >>

indicates to me your numerics have some serious problems.

--

Subject: Simple request; plotting problem

From: chip

Date: 26 Nov, 2009 20:22:31

Message: 3 of 3

Thanks for the effort. Yes, dMhdt and dMsdt are supposed to start as zero. Strangely though, I don't get the same 'errors' that you do. No matter, however. I will have access to the newer version of matlab which I know generates the correct plot, so I'll try it myself on that.
Much thanks again.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com