Error in code when using the Euler method

4 views (last 30 days)
Tawheed Uddin
Tawheed Uddin on 16 Mar 2022
Answered: Jan on 16 Mar 2022
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

Answers (1)

Jan
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.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!