A12

ENGR 17
Assignment 12
Due: Next Tuesday
Create an A12 folder to hold all your work. Make sure to save your figures in this folder
After solving each problem, copy any numeric answers into your script and comment out the whole problem
1)
Create a new script dillution.m
a) Using the modified Euler method from the diffeq demo file, solve for y(t) over the interval 0<=t<=10
This means you'll set up a vector of time samples as we did in the demo:
deltaT = 0.1 ; % step size
y(0)=0;
t=[0:deltaT:10]; % our vector of time values
Continue the script with a for loop that builds the solution vector y one cell at a time at each value of k over
the length of the time vector.
Remember that in calculating g1, we use the expression deltaT*dydt1 where dydt1 is the formula for
dy/dt using the current value of y, (that is, y(k) ) and the current value of t, (that is, t(k)). In calculating g2,
we use the expression deltaT*dydt2, where dydt2 is the formula for dy/dt at the next value of y, (that is,
y(k+1) ) using the projected value of y (that is, y(k) + g1 ) and the next t (that is, t(k+1) )
b) Still in diffusion.m, add more statements to solve the same problem a second time using the ode23 function.
For this step you'll first need to create a function file that computes the derivative of the concentration give
the current t and y. Call this function dillutionDot. Then, back in diffusion.m add statements that use the
ode23 function to create a second solution for y.
c) Finally, plot both solutions on the same plot and lable them with title, axes labels and a legend. If they
diverge wildly, you must debug your solutions!!
2) Create a script called spring.m
Use the state variable method to express the equation as two coupled first order equations in x1(t) and x2(t) and
use ode45 to solve them. You'll need to create a function file springDot.m that computes the derivative based
on t and x. Use the initial conditions y(0)=0 and y'(0)=0. Construct the solution over the range 0<=t<=4 seconds.
Plot your solution and identify the two curves with a legend. Indicate in your legend which curve is the solution
vector y and which curve is ydot
Redo your solution with the initial conditions y(0)=0 and y'(0)=10. What is the effect of an initial velocity on the
mass?
3) (Extra Credit 1 Point)
4) (Extra Credit 2 Points)