Error in code when using the Euler method
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Jan
2022년 3월 16일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!