Azzera filtri
Azzera filtri

Plot a function which contains a variable parameter

1 visualizzazione (ultimi 30 giorni)
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!!

Risposta accettata

KSSV
KSSV il 18 Giu 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 Commento
EldaEbrithil
EldaEbrithil il 18 Giu 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by