Error in code when using the Euler method
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
The line of code I am having trouble with is: u(n+1)=u(n)+dt*(cos(2*pi()*t).^2)-5*u.^2); T is an array which is why I have used the dot operator - the error message: unable to perform assignment because the left and right sides have a different number of elements. Would really appreciate any help
0 comentarios
Respuestas (1)
Jan
el 16 de Mzo. de 2022
Use te debugger to examine the problem:
dbstop if error
Run the code again until it stops at the failing line. Then check the sizes:
size(u(n) + dt*(cos(2*pi*t).^2)-5*u.^2)
If this is not a scalar, you cannot assign it to the scalar u(n+1). Maybe you want u(n+1, :) or u(:, n+1) instead.
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations 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!