Simulating a simple equation

2 ビュー (過去 30 日間)
Jason
Jason 2012 年 11 月 18 日
コメント済み: John BG 2018 年 5 月 6 日
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 件のコメント
John BG
John BG 2018 年 5 月 6 日
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

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2012 年 11 月 18 日
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 件のコメント
Jason
Jason 2012 年 11 月 18 日
編集済み: Walter Roberson 2012 年 11 月 18 日
Hi Walter. You are patient, thanks.
i have sorted the above to:
c=0.056;
e0=0.2;
e=-1:0.1:1;
cr=0:0.05:1;
co=cr*exp((e-e0)/c);
this still fails specifically because of the cr element but i dont know why if the exponential term also comprises 20 values
Walter Roberson
Walter Roberson 2012 年 11 月 18 日
Use .* for element-by-element multiplication.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by