Hi,
I'm new to Matlab so, I'm trying my best! Thank you in advance for the help.
This is my code:
frequency0 = 10e9;
lambda0 = 3e8 / frequency0;
l = 0.5 * lambda0;
l = l * 39.3701;
n = 10;
delta = l/n;
Z1 = 50;
Z2 = 100;
for x = [0:delta:l]
Z0 = Z1 + (Z2 - Z1)*(x/l);
Zin_linear = Z0 * (((Z2 * cos(B* x)) + (j * Z0 * sin(B * x))) / ((Z0 * cos(B*x)) + (j * Z2 * sin(B*x))));
Z2 = Zin_linear;
endfor
plot(x,Z0);
What I'm trying to do, is for each number in x, I want to calculate the Z0 and the Zin_linear. Then I want to take Z2 and replace it with Zin_linear and then calculate a new Z0 and I want to do this until we reach l. However, when I plot this, I get one point on the graph. What am I doing wrong?

 채택된 답변

Mathieu NOE
Mathieu NOE 2021년 3월 23일

1 개 추천

hello
this is the typical situation when you forget to index the variable used to do the plot after the for loop
just missing the real B value (not provided) , but the code seems to work now
all the best,
frequency0 = 10e9;
lambda0 = 3e8 / frequency0;
l = 0.5 * lambda0;
l = l * 39.3701;
n = 10;
delta = l/n;
Z1 = 50;
Z2 = 100;
x_list = (0:delta:l);
B = 1; % put the right value here
Z0_plot = zeros(size(x_list)); % preallocation (always better)
for ck = 1:numel(x_list)
x = x_list(ck);
Z0 = Z1 + (Z2 - Z1)*(x/l);
Zin_linear = Z0 * (((Z2 * cos(B* x)) + (1i * Z0 * sin(B * x))) / ((Z0 * cos(B*x)) + (1i * Z2 * sin(B*x))));
Z2 = Zin_linear;
% for storage and plot
Z0_plot(ck) = Z0;
end
plot(x_list,Z0_plot);

댓글 수: 2

Emily Hackett
Emily Hackett 2021년 3월 23일
Thank you so much!
Mathieu NOE
Mathieu NOE 2021년 3월 24일
you're welcome

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2021년 3월 23일

댓글:

2021년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by