改进的欧拉法matlab程序
时间: 2023-11-04 20:00:44 浏览: 133
改进的欧拉法matlab程序如下:
```matlab
function [y1, y2, y3, y4] = exam4_6(a, b, k)
h = (b - a) / k;
x = a:h:b;
[m, n] = size(x);
y1 = zeros(m, n);
y2 = zeros(m, n);
y3 = zeros(m, n);
y1(1) = 1;
y2(1) = 1;
y3(1) = 1;
for i = 1:n-1
x1 = x(i);
x2 = x(i+1);
y1(i+1) = y1(i) + h * ((sin(x1) - y1(i)) / x1);
end
for i = 1:n-1
x1 = x(i);
x2 = x(i+1);
yy = y2(i);
y2(i+1) = y2(i) + h * (sin(x1)/x1 - y2(i)/x1);
end
for i = 1:n-1
x1 = x(i);
x2 = x(i+1);
z1 = (sin(x1) - y3(i)) / x1;
yy = y3(i);
z2 = sin(x2) / x2 - yy / x2; y3(i+1) = y3(i) + h * 0.5 * (z1 + z2);
end
for i = 1:n
y4(i) = (exp(-x(i)) * exp(pi)) / 2 - (2^(1/2) * cos(x(i) + pi/4)) / 2;
end
end
```
阅读全文