I want to save all the values of e1 and e2 and then I want to plot them
1 回表示 (過去 30 日間)
古いコメントを表示
%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...
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!