DSolve[{y'[x]==((y[x])^2)+Sin[x],y[2]==0},y[x],{x,2,3}]

DSolve[{y'[x]==y[x]+Sin[x],y[2]==0},y[x],{x,2,3}]

yex[x_]:=-(((E^2) Cos[x]-(E^x) (Cos[2]+Sin[2])+(E^2) Sin[x])/(2 (E^2)))

Plot[yex[x],{x,2,3}]

f[x_,y_]:=y+Sin[x]
f[2,0]

%//N

yex[2]

%//N

0.2*0.909

f[2.2,0.1818]

yex[2.2]

0.1818-0.1912

0.1818+0.2*0.99

yex[2.4]

0.398812-0.3798

a=2.;b=3;
n=5;h=((b-a)/n);
f[x_,y_]:=y+Sin[x]
yex[x_]:=-(((E^2) Cos[x]-(E^x) (Cos[2]+Sin[2])+(E^2) Sin[x])/(2 (E^2)))
x=a;y=0;
Print["i = ", 0, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
For[i=1,i≤n,i++,
ynext=y+h*f[x,y];
x=x+h;
y=ynext;
Print["i = ", i, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
]

по-точно:

a=2.;b=3;
n=50;h=((b-a)/n);
f[x_,y_]:=y+Sin[x]
yex[x_]:=-(((E^2) Cos[x]-(E^x) (Cos[2]+Sin[2])+(E^2) Sin[x])/(2 (E^2)))
x=a;y=0;
Print["i = ", 0, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
For[i=1,i≤n,i++,
ynext=y+h*f[x,y];
x=x+h;
y=ynext;
Print["i = ", i, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
]

добавяме визуализация:

a=2.;b=3;
n=5;h=((b-a)/n);
f[x_,y_]:=y+Sin[x]
yex[x_]:=-(((E^2) Cos[x]-(E^x) (Cos[2]+Sin[2])+(E^2) Sin[x])/(2 (E^2)))
x=a;y=0;
points={{x,y}};
Print["i = ", 0, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
For[i=1,i≤n,i++,
ynext=y+h*f[x,y];
x=x+h;
y=ynext;
AppendTo[points,{x,y}];
Print["i = ", i, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
]
grp=ListPlot[points,PlotStyle->{Red,PointSize[0.025]}];
grex=Plot[yex[x],{x,2,3}];
Show[grp,grex]

a=2.;b=3;
n=50;h=((b-a)/n);
f[x_,y_]:=y+Sin[x]
yex[x_]:=-(((E^2) Cos[x]-(E^x) (Cos[2]+Sin[2])+(E^2) Sin[x])/(2 (E^2)))
x=a;y=0;
points={{x,y}};
Print["i = ", 0, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
For[i=1,i≤n,i++,
ynext=y+h*f[x,y];
x=x+h;
y=ynext;
AppendTo[points,{x,y}];
Print["i = ", i, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
]
grp=ListPlot[points,PlotStyle->{Red,PointSize[0.025]}];
grex=Plot[yex[x],{x,2,3}];
Show[grp,grex]

модифициран метод на Ойлер

a=2.;b=3;
n=5;h=((b-a)/n);
f[x_,y_]:=y+Sin[x]
yex[x_]:=-(((E^2) Cos[x]-(E^x) (Cos[2]+Sin[2])+(E^2) Sin[x])/(2 (E^2)))
x=a;y=0;
points={{x,y}};
Print["i = ", 0, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
For[i=1,i≤n,i++,
x12=x+h/2;
y12=y+(h/2)*f[x,y];
Print["междинна стъпка: ", " (Subscript[x, 1/2]) = ",x12, " (Subscript[y, 1/2]) = ",y12, " f((Subscript[x, 1/2]),(Subscript[y, 1/2])) = ",f[x12,y12]];
ynext=y+h*f[x12,y12];
x=x+h;
y=ynext;
AppendTo[points,{x,y}];
Print["i = ", i, " x = ",x, " y = ",y, " f(x,y) = ",f[x,y], " \!\(\*SubscriptBox[\(y\), \(точно\)]\) = ",yex[x], " err = ",Abs[y-yex[x]]]
]
grp=ListPlot[points,PlotStyle->{Red,PointSize[0.025]}];
grex=Plot[yex[x],{x,2,3}];
Show[grp,grex]