# Can anyone help ?

1 view (last 30 days)
Commented: Jeffrey Clark on 22 Apr 2022
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.
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));
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] ;
fprintf('%.af\n',y)
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
Jeffrey Clark on 22 Apr 2022
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:

### 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!

Translated by