Error in code when using the Euler method
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Jan
on 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 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!