MATLAB Code for Euler's Method
Hi,
Is there a way to write a matlab code for euler's method depending on 8 parameters so that it will plot an approx solution
function euler(XL, XR, YD, YU, X0, Y0, h, n), where
XL : the left-most x-coordinate of the plot.
XR : the right-most x-coordinate of the plot.
YD : the bottom y-coordinate of the plot.
YU : the top y-coordinate of the plot.
X0 : the x-coordinate of the initial point of the solution.
Y0 : the y-coordinate of the initial point of the solution.
h : the step-length used in the Euler's method.
n : the number of iterations to be taken of Euler's method.
I have tried to write a few code , but am not sure how to continue or where is wrong ...
function euler(XL, XR, YD, YU, X0, Y0, h, n)
clf
hold
axis([XL XR YD YU])
plot([XL XR] , [0 0] , 'red' , 'LineWidth' , 1)
plot([0 0] , [YD YU] , 'red' , 'LineWidth' , 1)
W=(XR-X0)/h;
for x=XL:W:XR
for y=YD:(YU-Y0)/h:YU
plot([X0 X0 +W/n], [Y0 Y0+h*sin(x+y)], 'LineWidth' , 1.5)
end
end
Is there a way to write a matlab code for euler's method depending on 8 parameters so that it will plot an approx solution
function euler(XL, XR, YD, YU, X0, Y0, h, n), where
XL : the left-most x-coordinate of the plot.
XR : the right-most x-coordinate of the plot.
YD : the bottom y-coordinate of the plot.
YU : the top y-coordinate of the plot.
X0 : the x-coordinate of the initial point of the solution.
Y0 : the y-coordinate of the initial point of the solution.
h : the step-length used in the Euler's method.
n : the number of iterations to be taken of Euler's method.
I have tried to write a few code , but am not sure how to continue or where is wrong ...
function euler(XL, XR, YD, YU, X0, Y0, h, n)
clf
hold
axis([XL XR YD YU])
plot([XL XR] , [0 0] , 'red' , 'LineWidth' , 1)
plot([0 0] , [YD YU] , 'red' , 'LineWidth' , 1)
W=(XR-X0)/h;
for x=XL:W:XR
for y=YD:(YU-Y0)/h:YU
plot([X0 X0 +W/n], [Y0 Y0+h*sin(x+y)], 'LineWidth' , 1.5)
end
end
0
Comments