CBE 162 Lab 1

F x2 12x 27 end then using an initial guess of 0

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Ashley Scott CBE 162 Lab 1 (a) First, we make an m ­file containing this: function [f] = root(x) %We must specify the polynomial. f = x^2 - 12*x + 27; end Then, using an initial guess of 0: To check To check for other roots, I increase the value of initial guess, and see that the roots of the polynomial are 3 and 9. This can be seen by the code to the right. Ashley Scott CBE 162 Lab 1 (b) function [dhdt ] = height( t,h ) %Initialize output matrix dhdt = zeros(size(h)); %Define constraints, F1 and F2 are no longer equal F1=3*cos(t) + 17; F2=4*sqrt(h); A=5; %area is constant dhdt(1)=F1/A - F2/A; end %Put this into the command window, with initial height value of 1m [t,h]=ode45(@height, [0 50], [1]); >> plot(t,h);xlabel('Time (min)');ylabel('Height (m)');title('Problem 3b') (c ) My m ­file: function [dC] = concentration(t,C) Ashley Scott CBE 162 Lab 1 %Initialize output matrix %C is a vector that contains Ca, Cb, Cab, and Cc %For the purposes of MATLAB, AB=AB* dC = zeros(size(C)); %Define constraints k1=.5; k2=2; k3=1; %Must state the system of ODEs, they are all interconnected %Set dC(1) for dCa dC(1)=-k1*C(1)*C(2) + k2*C(3); %Set dC(2) for dCb dC(2)=-k1*C(1)*C(2) + k2*C(3); %Set dC(3) for dCab* dC(3) =k1*C(1)*C(2) - k2*C(3) - k3*C(3); % Set dC(4) for dCc dC(4) = k3*C(3); end %Put in...
View Full Document

This document was uploaded on 03/04/2014.

Ask a homework question - tutors are online