Solve, using scilab, the Ordinary Differential Equation by the Adams-Bashforth method of…
- User
Solve, using scilab, the Ordinary Differential Equation by the Adams-Bashforth method of order 6y''(t)+23.8y''(t)+1.3y'(t)+0.5y(t)=8; y(0)=y'(0)=y'(0)=0; t on the interval [0, 400];
- Assistant
First, let's write the given ODE as a system of first order ODEs. To do that, let's set
y1(t) = y(t), y2(t) = y'(t), y3(t) = y''(t).
Then we have the following system of first order ODEs:
y1'(t) = y2(t), y2'(t) = y3(t), 6 * y3'(t) + 23.8 * y3(t) + 1.3 * y2(t) + 0.5 * y1(t) = 8.
We'll solve this system of first order ODEs using Scilab and the Adams-Bashforth method.
Here is the Scilab code:
function ydot = f(t, y) y1 = y(1) y2 = y(2) y3 = y(3) y1_dot = y2 y2_dot = y3 y3_dot = (8 - 0.5*y1 - 1.3*y2 - 23.8*y3)/6 ydot = [y1_dot; y2_dot; y3_dot] endfunction function AdamsBashforth6(f, y0, t) n = length(t) yt = y0 m = length(y0) h = t(2)-t(1) A = [-4277, 7923, -11081, 9499, -577, -1671 252270, -427674, 542979, -386959, 101839, -13646 109476, 209300, 315000, 696000, 362000, 0] / 2772 // rk4 for initial values for i = 1:5 k1 = f(t(i), yt(:,i)) k2 = f(t(i) + 0.5*h, yt(:,i) + 0.5*h*k1) k3 = f(t(i) + 0.5*h, yt(:,i) + 0.5*h*k2) k4 = f(t(i) + h, yt(:,i) + h*k3) yt(:,i+1) = yt(:,i) + (1/6)*h*(k1 + 2*k2 + 2*k3 + k4) end // main loop for Adams-Bashforth for i = 6:n-1 fs = zeros(m, 6) for j = 1:6 fs(:,j) = f(t(i-j+1), yt(:,i-j+1)) end yt(:,i+1) = yt(:,i) + h*fs*A end yt endfunction y0 = [0; 0; 0] t = linspace(0, 400, 401)' result = AdamsBashforth6(f, y0, t) disp(result(1:10,:))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.