Error in code when using the Euler method
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Jan
il 16 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!