Borrar filtros
Borrar filtros

Plot a function which contains a variable parameter

1 visualización (últimos 30 días)
EldaEbrithil
EldaEbrithil el 18 de Jun. de 2021
Comentada: EldaEbrithil el 18 de Jun. de 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!!

Respuesta aceptada

KSSV
KSSV el 18 de Jun. de 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 comentario
EldaEbrithil
EldaEbrithil el 18 de Jun. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by