Error as Function definitions are not permitted in this context.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
vetri veeran
el 4 de Abr. de 2017
Respondida: KSSV
el 4 de Abr. de 2017
Hi all,
I am getting error as Function definitions are not permitted in this context.
My code:
function dydt = odefcn(t,y,A,B)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t*y(1);
A= 1;
B= 2;
tspan=[0 5];
y0 = [0 0.01];
[t,y]= ode15s(@(t,y) odefcn(t,y,A,B), tspan, y0);
plot(t,y(:,1),'-o',t,y(:,2),'-.' )
Could you please help me.
0 comentarios
Respuesta aceptada
KSSV
el 4 de Abr. de 2017
You have two options:
function Main
A= 1;
B= 2;
tspan=[0 5];
y0 = [0 0.01];
[t,y]= ode15s(@(t,y) odefcn(t,y,A,B), tspan, y0);
plot(t,y(:,1),'-o',t,y(:,2),'-.' )
end
function dydt = odefcn(t,y,A,B)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t*y(1);
end
Save the above lines in the m file and name it Main.m and run.
Or save the odefcn function alone in as function in file odefcn.m and call it file.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Language Fundamentals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!