Can anyone help ?
조회 수: 1 (최근 30일)
이전 댓글 표시
i want to calculate the solution of the following cauchy problem :
y'(t)=1+t-y(t) t in[0,1]
but i have this error can anyone help me:
FZERO cannot continue because user supplied function_handle ==>
@(x)dot(a,y(i:-1:i-p))+h*dot(b(1:end-1),f(t(i:-1:i-p),y(i:-1:i-p)))-x+h*b(end)*f(t(i+1),x) failed
with the error below.
Matrix dimensions must agree.
Error in adamsMp2o3 (line 14)
y(i+1)=fzero(@(x)dot(a,y(i:-1:i-p))+h*dot(b(1:end-1),f(t(i:-1:i-p),y(i:-1:i-p)))-x+h*b(end)*f(t(i+1),x),y(i));
Error in ppadamasmoultonordre3 (line 26)
[t,y]=adamsMp2o3(a,b,f,y0,t,n,af,h)
f=@(t,y)(1+t-y);
% les données
Tf=1;
t0=0;
h=0.1;
n=(Tf-t0)/h;
t=linspace(t0,Tf,n+1);
af=3;
y0=0;
a=[1,0];
b=[8/12 -1/12 5/12];
%b=[2/3 -1/12 5/12] ;
[t,y]=adamsMp2o3(a,b,f,y0,t,n,af,h)
fprintf('%.af\n',y)
function [t,y]=adamsMp2o3(a,b,f,y0,t,n,af,h)
p=length(a)-1;
y(1)=y0;
t=t';
k1=f(t(1),y(1));
k2=f(t(1)+h/2,y(1)+(h/2)*k1);
k3=f(t(1)+h/2,y(1)+(h/2)*k2);
k4=f(t(1)+h,y(1)+h*k3);
y(2)=y(1)+(h/6)*(k1+2*k2+2*k3+k4);
for i=p+1:n
y(i+1)=fzero(@(x)dot(a,y(i:-1:i-p))+h*dot(b(1:end-1),f(t(i:-1:i-p),y(i:-1:i-p)))-x+h*b(end)*f(t(i+1),x),y(i));
end
댓글 수: 1
Jeffrey Clark
2022년 4월 22일
When looking for such problems I usually rerun useing "Pause on Errors" enabled which will allow you to examine the variables and try parts of the equation to see what is failing. You can then traceback in your code to see how the data got created incorrectly:
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!