Plot a function which contains a variable parameter

조회 수: 3 (최근 30일)
EldaEbrithil
EldaEbrithil 2021년 6월 18일
댓글: EldaEbrithil 2021년 6월 18일
Hi all
assuming to have a function like that:
function f=Myfun(t,a,b)
a=2*t;
f=t^2+a-b;
end
where b is a variable parameter [b(1)=0,b(2)=3,b(3)=7...]. How can I plot f for each values of b, in a certain time range, using a for loop?
Thank you very much
Reagards!!

채택된 답변

KSSV
KSSV 2021년 6월 18일
It is your home work....read about for loop and aray indexing in MATLAB. Given eblow a demo example. Extend this to your case.
a = [1 2 3] ;
th = linspace(0,2*pi) ;
X = zeros(length(a),length(th)) ;
for i = 1:length(a)
X(i,:) = a(i)*sin(th) ;
end
plot(th,X)
  댓글 수: 1
EldaEbrithil
EldaEbrithil 2021년 6월 18일
T=10;
b=[1,2,3,-4,5,6,7,-80];
t=[0:0.1:T].*ones(length(b),length(T+1));
Beta=zeros(length(b),length(t));
for i=1:length(b)
for j=1:length(t)
Beta(i,j)=PROVA(t(i,j),b(i));
end
end
for i=1:length(b)
figure(1)
plot(t(i,:),Beta(i,:))
hold on
end
function Beta=PROVA(t,b)
a=t;
Beta=a*t^2+b;
end
Thank you very much KSSV

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by