Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hw2_246
- clc
- hw2_246_1
- hw2_246_2
- function hw2_246_1
- %% Part a
- syms y(t)
- dsolve('D2y + y*2 = 0');
- Dy = diff(y);
- sols = sym(zeros(11,1));
- for x = 1:10
- sols(x) = dsolve('D2y + y*2 = 0', y(0) == 0, Dy(0) == x/10);
- end
- figure
- hold on
- for x = 1:11
- ezplot(sols(x), [0,10])
- end
- hold off
- %% Part b
- syms y(t)
- Dy = diff(y);
- figure
- hold on
- ezplot(dsolve('D2y + Dy + y*2 = 0', y(0)== 0, Dy(0) == 2), [0 40])
- %ezplot(dsolve('D2y + Dy*2*sqrt(2) + y*2 = 0', y(0) == 2, Dy(0) == 2), [0 40])
- %second case doesn't want to work for whatever reason
- ezplot(dsolve('D2y + Dy*4 + y*2 = 0', y(0)== 2, Dy(0) == 2), [0 40])
- hold off
- %% Part c
- syms y(t)
- figure
- hold on
- ezplot('2*cos(sqrt(2)*t) + (sin(sqrt(2)*t)*sqrt(2))+(sin(7*t)-cos(sqrt(2)*t))/(-45)', [0, 40])
- ezplot('2*cos(sqrt(2)*t) + (sin(sqrt(2)*t)*sqrt(2))+t*sin(sqrt(2)*t)/(2*sqrt(2))', [0, 40])
- hold off
- %% Part d
- syms y(t)
- function hw2_246_2
- hold on
- for k = 1:5
- m(k) = -2+(k-1);
- n(k) = -1+.5*(k-1);
- [t,x] = ode45('F',[-3,3],[m(k),n(k)]);
- plot(t,x(:,1))
- end
- hold off
- function xp = F(t,x)
- xp = zeros(2,1);
- xp(1) = x(2);
- xp(2) = -t^3*x(2)-x(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement