Simulating a simple equation
이전 댓글 표시
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
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

채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!