# hw25 - w=2.0; dy = zeros(2,1); % a column vector dy(1)=y(2);

This preview shows pages 1–7. Sign up to view the full content.

w=.5 w=1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
w=1.5 w=2
%example numerical solution of 1st order ODE %dy/dt=-k(u-T0+T1cos(wt)), y(0)=40 y0=40; %initial value tspan= [0:1:400]; %creates vector of times for plotting [t,y]=ode23( 'function_hw4' ,tspan,y0); %computes numerical solution and %returns t and y vectors hold off %starts new plot plot(t,y, 'o' ) %plots t vs y with open symbol %compare with analytical solution c= 40; w= pi/66; % ID number ends in 66 k= 0.02; T0= 20; T1= 40; yanaly= T0 - k*T1*((k*cos(w*t))+w*(sin(w*t))/(k^2+w^2)) + 40*exp(-k*t); hold on %next plot overlays prior plot plot(t,yanaly) %plots analytical solution w/ solid line xlabel( 't' ) ylabel( 'y' ) figure R = zeros(1,4); w = zeros(1,4); R(1) = 1.125; R(2) = 1.9; R(3) = .8; R(4) = .34 w(1) = .5; w(2) = 1; w(3) = 1.5; w(4) = 2; plot(w,R) xlabel( 'w' ) ylabel( 'R' ) ______________________________________________________ function dy=derivative(t,y)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: w=2.0; dy = zeros(2,1); % a column vector dy(1)=y(2); dy(2)=cos(w*t)-.2*y(2)-y(1)-.2*y(1)^3; w=.5 w =1 w=1.5 w=2 %3.8.25.c %numerical integration of 2nd order equation %u&quot;+.2u'+u+ .2u^3=cos(wt), u(0)=0, u'(0)=0 %from 0 to 70, with plotting steps of 0.1 time units u0=0; v0=0; Y0=[u0 v0]; %initial conditions Tspan=[0:.1:150]; %times for plotting [T,Y]=ode23( 'derivative2' ,Tspan,Y0); figure(1) plot(T,Y(:,1)) xlabel( 't' ) ylabel( 'u' ) figure R = zeros(1,4); w = zeros(1,4); R(1) = 1.825; R(2) = 2.80; R(3) = 2.10; R(4) = 0.62; w(1) = .5; w(2) = 1; w(3) = 1.5; w(4) = 2; plot(w,R) xlabel( 'w' ) ylabel( 'R' ) ______________________________________________________ function dy=derivative2(t,y) w=2; dy = zeros(2,1); % a column vector dy(1)=y(2); dy(2)=cos(w*t)-y(1)-.2*y(1)^3;...
View Full Document

## hw25 - w=2.0; dy = zeros(2,1); % a column vector dy(1)=y(2);

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online