plot the graph of function

3 ビュー (過去 30 日間)
shiv gaur
shiv gaur 2022 年 1 月 29 日
コメント済み: Walter Roberson 2022 年 1 月 31 日
l=633;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
for i=1:length(theta)
for j=1:length(da)
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
disp(y)
end
end
plot(da,y )
error message pl plot between da vs y and dy/da vs da
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-100.
  3 件のコメント
shiv gaur
shiv gaur 2022 年 1 月 29 日
c is =1
shiv gaur
shiv gaur 2022 年 1 月 29 日
how to plot dy/dda vs da

サインインしてコメントする。

採用された回答

Kevin Hanekom
Kevin Hanekom 2022 年 1 月 29 日
clc;clear;close all;
l=633;
c = 1;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
for i=1:length(theta)
iter = 0;
for j=1:length(da)
iter
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
% disp(y);
iter = iter + 1;
end
end
plot(da,y )
What exactly is wrong?
  2 件のコメント
shiv gaur
shiv gaur 2022 年 1 月 29 日
編集済み: Walter Roberson 2022 年 1 月 31 日
this program is working pl help one pl plot da vs dy/dda
why this is not working in function define
clc;clear;close all;
l=633;
c = 1;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
function y=f(theta,da)
for i=1:length(theta)
iter = 0;
for j=1:length(da)
iter
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
% disp(y);
iter = iter + 1;
plot(da,y )
end
end
end
your program in not working pl help
Walter Roberson
Walter Roberson 2022 年 1 月 31 日
That code never calls the function f
Reminder: your y is a 2D array that is changing in size as you go (since you do not pre-allocate). And each time you assign to a new y(i,j) location, you are plotting using the constant-sized vector da as the independent variable, and using all of the changing-size y as the dependent variable. That is going to run into size mismatches, and is also going to be attempting to plot locations in y that have not been explicitly given a value yet.
What is the point of doing the plot inside the double nested loop?
It might make sense to plot at the end of the double nested loop.
... but it would probably make more sense to return y to the calling function and let the calling function plot whatever it wants.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by