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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by