
Simulating a simple equation
1 view (last 30 days)
Show older comments
I am new fairly new to Matlab - a light user for a few years and know only the basics.
I am trying to use it to simulate a trend in two parameters with a third and to then plot the result.
All i want to do, at least to start with, is to simulate the trend in Co and Cr with E according to:
c=0.057;% a constant
E0=0;
E=-0.5:0.05:0.5;
Co=linspace(0,1,0.01); %dependent variable
Cr=linspace (0,1,0.01); %second dependent variable
E=E0+(c*log(Co/Cr));
plot(E,Co,'b*-')
i think lines 3&4 are equivalent ways of specifying a range of numbers.
This fails with an error related to the vectors being of unequal length. f, by "plotting vectors" the software means E and Co then i don't understand why these would need to be "the same length" (indeed this error remains if i confine them to the same numerical range anyway).
My questions are:
(i) am i going about this supposedly simple task in the right way and (ii) what specifically am i doing wrong
any help hugely appreciated
1 Comment
John BG
on 6 May 2018
Hi Jason
1.
you are plugging the function output E into what plot expects to be the reference vector of the plotting, therefore, the plot shows up a vertical line:
c=0.057; % obvious constant
E0=0;
E=-0.5:0.05:0.5;
Co=[.01:.01:1]
Cr=[.01:.01:1]
E=E0+(c*log(Co./Cr));
plot(E,Co,'b*-')
so instead of
plot(E,Co,'b*-')
E, the function, has to be the 2nd input field of plot, or the only input field of plot, setting parameters aside.
plot(Co,E,'b*-')
2.
This is still pretty flat, because Co==Cr
isequal(Co,Cr)
ans =
logical
1
don't you really mean E to be something like this?
c=0.057;% a constant
E0=0;
E=-0.5:0.05:0.5;
Co=[.01:.01:1]
Cr=[.01:.01:1]
E=E0+(Co.*log(c./Cr));
plot(Co,E,'b*-');grid on

Accepted Answer
Walter Roberson
on 18 Nov 2012
In your line
E=E0+(c*log(Co/Cr));
the / operation is matrix division, not element-by-element division. Change the line to
E = E0 + (c * log(Co ./ Cr));
6 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!