Plot a function which contains a variable parameter

3 次查看(过去 30 天)
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