Parse error at zeta.
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to solve a differential equation using MATLAB however I am having trouble. there is a red error next to Zeta- the error is as follows:
This statement is not inside any function. Parse error at zeta. usage might be invalid MATLAB syntax
Thank you.
function dydt= odefcn(t,y,f,r,zeta)
dydt=zeros(2,1);
dydt(1)=y(2);
dydt(2)=fsin(r*t)-2.\z.y(2)-sin(y);
end
%parameters and initial conditions
zeta = 0.5;
f = 0.40 + (0.1: 0.1: 0.4);
r = (0.3: 0.3: 1.5);
y(0)=0.5;
dy/dt(0)=0;
tspan = [0 1000]
options = odeset('RelTol',1e-6,'AbsTol' 1e-9 1e-9]);
[t,y] = ode45(@(t,y) odefcn(t,y,f,r,zeta), tspan, y0);
3 comentarios
Respuestas (2)
Star Strider
el 27 de Dic. de 2021
There appear to be errors in ‘odefcn’ that need to be addressed.
I have no idea if ‘f’ and ‘r’ are to be evaluated together (as I did here), or if they need to be created using ndgrid as:
[fm,rm] = ndgrid(f,r);
and then evaluated as:
fv = fm(:);
rv = rm(:);
with:
N = numel(fv);
for k = 1:N
[t,y{k}] = ode45(@(t,y) odefcn(t,y,fv(k),rv(k),zeta), tspan, y0);
end
so every value of each is evalueated with evary value of the other, so I defer that to you.
%parameters and initial conditions
zeta = 0.5;
% f = 0.40 + (0.1: 0.1: 0.4)
N = 5;
f = linspace(0.4, 0.8, N);
% r = (0.3: 0.3: 1.5)
r = linspace(1.3, 1.5, N);
% y(0)=0.5;
% dydt(0)=0;
y0 = [0.5, 0];
% tspan = [0 1000];
tspan = linspace(0, 1000, 250);
options = odeset('RelTol',1e-6,'AbsTol', 1e-9);
for k = 1:N
[t,y{k}] = ode45(@(t,y) odefcn(t,y,f(k),r(k),zeta), tspan, y0);
end
figure
for k = 1:N
subplot(N,1,k)
plot(t,y{k})
grid
title(sprintf('f = %.1f, r = %.1f',f(k),r(k)))
legend('$\dot{y_2}$','$y_2$', 'Interpreter','latex', 'Location','bestoutside')
end
function dydt= odefcn(t,y,f,r,zeta)
dydt=zeros(2,1);
dydt(1)=y(2);
dydt(2)=f.*sin(r*t)-2.\zeta.*y(2)-sin(y(1));
end
The code runs without error, however ‘odefcn’ needs to be carefully edited to be certain it is correct.
.
0 comentarios
Image Analyst
el 27 de Dic. de 2021
There is no zeroeth element like you try to assign here:
y(0)=0.5;
The first index is 1, not 0.
This is not valid syntax:
dy/dt(0)=0;
not sure what you were thinking there but you might be able to delete the whole line.
This seems to be missing a command and left bracket and maybe some other stuff
options = odeset('RelTol',1e-6,'AbsTol' 1e-9 1e-9]);
Like maybe it should be:
options = odeset('RelTol', 1e-6, 'AbsTol', [1e-9, 1e-9]);
That's a start anyway. Fix those and then there may be other errors but just work your way through them one at a time.
0 comentarios
Ver también
Categorías
Más información sobre Entering Commands 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!
