Can anyone help ?

1 vue (au cours des 30 derniers jours)
diadalina
diadalina le 21 Avr 2022
Commenté : Jeffrey Clark le 22 Avr 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.
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 commentaire
Jeffrey Clark
Jeffrey Clark le 22 Avr 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:

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by