Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ x, v ] = AdamsBashforthUklDwa(xp, y0, h )
- f=@(x,v) v;
- g=@(x,v) -x;
- x(1) = y0(1);
- v(1) = y0(2);
- n = length(xp(1):h:xp(2));
- for i = 1:n-1
- x(i + 1) = x(i) + h;
- v(i + 1) = v(i) + h;
- if i == 1
- x(i + 1) = x(i) + h * f(x(i), v(i));
- v(i + 1) = v(i) + h * g(x(i), v(i));
- elseif i >= 2
- x(i + 1) = x(i) + h * (1.5*f(x(i), v(i)) - 0.5*f(x(i-1), v(i-1)));
- v(i + 1) = v(i) + h * (1.5*g(x(i), v(i)) - 0.5*g(x(i-1), v(i-1)));
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement