CHE132B MATLAB Tutorial

CHE132B MATLAB Tutorial - Q=400 A=1200 deltat=0.5...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
ChE 132B Numerical Methods in Chemical Engineering Fall 2005 MATLAB Tutorial & Homework Assignment t=0 y=0 Q=400 A=1200 dydt = 3*(Q/A)*sin(t)^2-(Q/A) deltat=0.5 y = y + dydt*deltat t = t + deltat dydt = 3*(Q/A)*sin(t)^2-(Q/A) y = y + dydt*deltat t = t + deltat dydt = 3*(Q/A)*sin(t)^2-(Q/A) y = y + dydt*deltat % And So on and So Forth % Well, that's not that much fun. Can we get this thing to do it for us? % What if we can call up the derivative as a function dydt(t,Q,A) rather than "typing" it in all the time? % Two concepts: function files and script files. % We want dydt to be a function dydt(t). Make a matlab m file: -------------------------------------------------- function deriv=dydt(t, Q, A) deriv = 3*(Q/A)*sin(t).^2-(Q/A); % The semicolon makes it invisible ---------------------------------------------------
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Q=400 A=1200 deltat=0.5 t=0:deltat:5 t=0:.5:5 t=0:deltat:5 y=zeros(1,11) for i=1:10 y(i+1)=y(i)+dydt(t(i),Q,A).*deltat end plot(t,y) % We can actually turn this whole thing into a script by simply saving it as lesson.m and running it from the command line ChE 132B Numerical Methods in Chemical Engineering Fall 2005 Homework Assignment: Modify the program so that instead of a fixed coefficient for the input flowrate (the 3) it is actually a variable you can pass to the derivative function. Using a time step of 0.1 days, find the coefficient in the input flowrate that allows the system to remain neutral (i.e., it doesnt fill up or empty to infinity, but rather just oscillates between a minimum and a maximum). How tall of a tank do you need to order from a reputable vendor (in meters)?...
View Full Document

This note was uploaded on 12/29/2011 for the course CHE 132b taught by Professor Ceweb during the Fall '09 term at UCSB.

Page1 / 2

CHE132B MATLAB Tutorial - Q=400 A=1200 deltat=0.5...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online