MATLAB Answers

0

I want to save all the values of e1 and e2 and then I want to plot them

Ram kumar T A さんによって質問されました 2019 年 7 月 10 日
最新アクティビティ dpb
さんによって コメントされました 2019 年 7 月 10 日
%clc
%close all
%clear
%Steel
n = 0.22;
r = 0.9;
for a = -1:1;
nr1 = (1+r*(1-a))*(1-(2*r*a/1+r)+a^2);
nr2 = ((1+r)*a-r)*(1-(2*r*a/1+r)+a^2);
dr = (1+r)*(1+a)*(1-((1+4*r+2*r^2)*a/(1+r)^2)+a^2);
e1 = (nr1/dr)*n;
e2 = (nr2/dr)*n;
end;
plot(e2,e1);

  1 件のコメント

dpb
2019 年 7 月 10 日
NB:
a=-1:1;
will return only three points, -1, 0, 1 which won't make much of a smooth plot for anything but a straight line.
NB2:
S Strider's solution via linspace will introduce 100 points between the bounds, enough to show the shape.
NB3:
in
nr1 = (1+r*(1-a))*(1-(2*r*a/1+r)+a^2);
the term (2*r*a/1+r) is same as 2*r*a+r, check for missing parentheses around the 1+r term that I'm guessing is supposed to be the divisor...

サインイン to comment.

1 件の回答

回答者: Star Strider
2019 年 7 月 10 日
 採用された回答

There are several ways to approach this.
This causes the least disruption to the code you posted:
n = 0.22;
r = 0.9;
av = linspace(-1, 1);
for k = 1:numel(av)
a = av(k);
nr1 = (1+r*(1-a))*(1-(2*r*a/1+r)+a^2);
nr2 = ((1+r)*a-r)*(1-(2*r*a/1+r)+a^2);
dr = (1+r)*(1+a)*(1-((1+4*r+2*r^2)*a/(1+r)^2)+a^2);
e1(k) = (nr1/dr)*n;
e2(k) = (nr2/dr)*n;
end
figure
plot(e2,e1)
grid
Experiment to get the result you want.

  0 件のコメント

サインイン to comment.



Translated by