MATLAB Answers

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

Ram kumar T A

### Ram kumar T A (view profile)

さんによって質問されました 2019 年 7 月 10 日

### dpb (view profile)

さんによって コメントされました 2019 年 7 月 10 日
Star Strider

### Star Strider (view profile)

さんの 回答が採用されました
%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);

dpb

### dpb (view profile)

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 (view profile)

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