IT1005. Lab session on week 11 ( 7 th meeting) 1 or 2 more weeks to go…. Lab 7 – Quick Check. Have you all received my reply for lab 7? Of course not . I have not finished grading your submissions yet >.< I have important research paper deadline >.< http://www.cs.mu.oz.au/cp2008/
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Lab session on week 11 (7th meeting)
1 or 2 more weeks to go…
Q1. A. Transform the non standard set of Linear Equations into standard format:
-(Q+k*V) *CA1 + 0 *CA2 + 0 *CA3 + 0 *CA4 = -Q*CA0
Q *CA1 -(Q+k*V) *CA2 + 0 *CA3 + 0 *CA4 = 0
0 *CA1 + Q *CA2 -(Q+k*V) *CA3 + 0 *CA4 = 0
0 *CA1 + 0 *CA2 + Q *CA3 -(Q+k*V) *CA4 = 0
Q1. B. Convert the standard format into matrix format. Another straightforward task:
[ -(Q+k*V) 000 ] *[CA1] = [-Q*CA0 ]
[ Q -(Q+k*V) 00 ] [CA2] [0 ]
[ 0 Q -(Q+k*V)0 ] [CA3] [0 ]
[ 0 0 Q-(Q+k*V) ] [CA4] [0 ]
Q1. C. You just need to do:
V = 1; Q = 0.01; CA0 = 10; k = 0.01;
A = [-(Q+k*V) 0 0 0; Q -(Q+k*V) 0 0; 0 Q -(Q+k*V) 0; 0 0 Q -(Q+k*V)];
b = [-Q*CA0; 0; 0; 0];
x = A\b % you should get x = [5; 2.5; 1.25; 0.625], x = inv(A) * b is NOT encouraged!
% Using fsolve for this is also not encouraged!
Q2. A. CSTR_input.m
Answer is very generic, similar to read_input.m in L6.Q2 (Car Simulation)
Q2. B. CSTR_matrix.m
% This is my geek version, do NOT USE THIS VERSION (too confusing for novice)!
function [A b] = CSTR_matrix(Q, CA0, V, k, N)
A = diag(repmat(-(Q+k*V),1,N)) + diag(repmat(Q,1,N-1),-1); % This is a bit crazy :$
b = zeros(N,1); b(1) = -Q*CA0;
Q2. C. CSTR_soln.m
clear; clc; clf; % New trick, but important ! Clear everything before starting our program!
[Q CA0 V k N] = CSTR_input();
[A b] = CSTR_matrix(Q, CA0, V, k, N);
plot(A\b,'o'); % I prefer not to connect the plot with line, but it is ok if you do so.
title('CA of each tank'); xlabel('Tank no k'); ylabel('CA_k'); % Good for CSTR_plot.m
axis([0.5 N+0.5 0 CA0]); % Fix y axis so that it is consistent across 4 plots (same CA0!)
Plot A against B means thatA is the Y axis, B is the X axis!
Should just stop here (n = 4) for case 1
Q3. Type these at command window:
syms x y; % no need to say syms f1 f2, the next two lines will create f1 and f2 anyway
f1 = x^2 * y^2 - 2*x - 1;
f2 = x^2 - y^2 - 1;
[a b] = solve(f1,f2); % or >> s = solve(f1,f2); a = s.x; b = s.y;
eval(a), eval(b) % convert the symbolic values to numeric values, these are the roots
Q4. Create this function
function F = lab07d(x)
F(1) = sin(x(1)) + x(2)^2 + log(x(3)) - 7;
F(2) = 3*x(1) + 2^(x(2)) + 1 - x(3)^3;
F(3) = x(1) + x(2) + x(3) - 5;
At command window (wild guesses will likely give you many imaginary numbers):
fsolve(@lab07d, [1 1 1]) x=0.5991, y=2.3959, z=2.0050
fsolve(@lab07d, [5 -1 1]) x = 5.1004, y = -2.6442, z= 2.5438
function dydt = bla(t,y) % always have at least these two arguments
% explain to Matlab how to derive dy/dt! Can be for coupled ODEs!
dydt = dydt'; % always return a column vector!
[t, y] = ode45(@bla, [tStart tEnd], IVs); % IVs is a column vector for coupled ODEs!
plot(t,y(:,1)); % we can immediately plot the results (also in column vector!)