Effacer les filtres
Effacer les filtres

Plot a function which contains a variable parameter

11 vues (au cours des 30 derniers jours)
EldaEbrithil
EldaEbrithil le 18 Juin 2021
Commenté : EldaEbrithil le 18 Juin 2021
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!!

Réponse acceptée

KSSV
KSSV le 18 Juin 2021
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 commentaire
EldaEbrithil
EldaEbrithil le 18 Juin 2021
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by