IT1005

1 / 12

IT1005 - PowerPoint PPT Presentation

IT1005. Lab session on week 13 (9 th /last meeting) After this, good bye…. Agenda. Review of Lab 8 Full review of IT1005 syllabus A very very quick review of fmincon. Mind mapping, in 10 minutes Past year paper discussion. Lab 8 - Review . Q1. A. fzero to find roots.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about 'IT1005' - monisha

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.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

IT1005

Lab session on week 13 (9th/last meeting)

After this, good bye…

Agenda
• Review of Lab 8
• Full review of IT1005 syllabus
• A very very quick review of fmincon.
• Mind mapping, in 10 minutes
• Past year paper discussion
Lab 8 - Review

Q1. A. fzero to find roots.

You are looking for positive root, then do not start fzero using negative guess, e.g. -1000?

Q1. B. fzero with parameter c. Plot c and roots.

Loop through various value of c, call fzero for each different c!

Q1. C. Use polyfit to fit the resulting plot of Q1. B.

4th or 5th order polynomial is already sufficient. This is a bit subjective though.

Q2. A. function that counts least square error of the y data and the y model.Geek version can be used here.

Q2. B. using fminsearch to find k1, k2, k3 that minimize the function value created in Q2. A.k1 = 5, k2 = -0.2, k3 = 7Your plot of y data and y model should more or less fit with each other!

Application 7: Optimization

How to use fmincon:

• Create a dedicated function to compute the objective value as usual.
• [x f] = fmincon(@(x) function_handle(x), IGs, A, B, C, D, LB, UB);
• IGs = a column vector of Initial Guesses for x.
• A, B = the inequality constraints, written like Linear Algebra standard format.
• C, D = the equality constraints
• LB, UB = the lower bound and upper bound for each variable x.
• This technique is not tested anywhere else so probably appear in the final exam…
Full Review of Our IT1005 (1)

This is the “linear version”, the “first part” of the semester:

• Top Down Design: Big Steps (at least input/process/output), Small Steps.
• This is called “programming methodology” (method to do programming).
• Introduction to Matlab environment, a powerful software!
• Data structure: simple variables (1x1 matrix); matrix/array/vector (+ manipulation!).
• Remember that Matlab (and computer) is imprecise (floating point).
• Basic commands: input, disp, sprintf, maths (BODMAS, logical/relational), %, etc.
• Debugging tool: breakpoint, workspace, etc.
• Control Structure:
• Sequence, Decision (if-elseif-else/switch-case/try-catch), Repetition (for/while).
• Function: M-files, Modularize your program
• The art of coding:
• Indentation, white spacing, no trivial comments, modular.
• Mathematical modeling:
• Spidey fall, car up in a slope, etc.
Full Review of Our IT1005 (2)

This is the “linear version”, the “second part” of the semester:

• Applications (solvers):
• Roots Finding (roots, fzero, fsolve, solve), Linear Algebra (A-1*b, \), Symbolic Maths (syms, diff, int, expand, factor, solve, etc), plotting tools (plot, title, xlabel, ylabel, legend, subplot), Ordinary Differential Equations: IVP (ode45, ode15s, etc), Math (sin, quad, abs, etc), Curve Fitting (polyfit, polyval), Optimization (fminsearch, fmincon), etc
• To use solvers like fsolve, ode45, ode15s, fminsearch, fmincon, you need to write a dedicated function M-file that has peculiar syntax but standard.

function retVal = fun_name(x)retVal(1) = do something with x(1);…retVal(numel(x)) = do something with x(numel(x));retVal = retVal’; % always return a column vector.

• To use fzero, fsolve, fminsearch, fmincon, etc, you need to supply“initial guess”, wrong guess will lead to non solution (fzero, fsolve) orlocal optima (fminsearch, fmincon).
Full Review of Our IT1005 (3)

This is the “linear version”, link to the “future”:

• Those that you have just learned in IT1005 are still ‘on surface’, just ‘tip ofthe iceberg’. We spare you from gory details until level 2 or level 3 :D.
• Actually, we have looked at some details already 
• mean/var  ah, more or less the same with our my_mean/my_var
• sort  a much better version than our bubble sort my_sort2
• ode45  eulerODE, just that more precise and faster.
• quad  a better version than traprule2.
• polyfit  we have simulate this using fminsearch to get least square fit.
• etc
• In the future, (perhaps) you will learn the following stuffs:
• Newton-Raphson, Runge-Kutta, etc, in module CNXXXX, CNYYYY, bla bla…
• A better way to explain this is via mind map(do you know this?)
• http://www.comp.nus.edu.sg/~stevenha/myteaching/IT1005_mindmap.png
Past Paper Discussion
• We only have one sample, Apr/May 2007.
• But note that last year, the lecturers were the same!
• So, similar style is expected.
• I give 15 minutes for you all to read the past papers for those who have not do so.
• Go to my website/NUS digital library to download the past paper.
• For those who have done past paper, do the question in the next slide!
• We will then discuss the answers until time is up.
Extra Question
• Robin hood is standing on a rock with height H. Assuming his hand is about 1 m above that rock, that means the arrow has initial height H+1.Then Robin shots his arrow at angle A radian with initial velocity IV…
• Create a Matlab program to simulate this physical model,and tell us what is the distance x? (assume g = 9.8 m/s2)
• If H = 10m, A = 30 degrees (convert to radian), IV = 30m/s.
• If H = 10m, A = 60 degrees (convert to radian), IV = 30m/s.
Combining Motion
• Vy = V*sin(A)  vertical component
• Vx = V*cos(A)  horizontal component
• Remember that A must be in radians!
• H = h0 + Vy*t – 1/2*g*t^2
• Find t, the time for the arrow to hit the ground, starting from h+1…
• Use roots to get the root t of this simple 2nd order polynomial.
• Take the positive root t.
• x = Vx*t;
• Multiple the positive root t with Vx to get the horizontal displacement x.
What is the style of past paper?
• It starts with some MCQ…
• MCQ tends to confuse us, many answers seems ok?
• Trick to do better for MCQ questions: remove the impossible options first (options that you are 100% sure that they are wrong).
• If you are left with one option, quickly select it.
• But if you still have more than one options, do the next questions first,at the end of the test, re-do it again or do roulette wheel selection or coin flip,this is better than using your (often misleading) assumptions!
• With 3 essays that do not look like programming test at the beginning.
• Math/Physics/Chemical Engineering questions in computer model.
• So, it is best to revisit some of your A-level knowledge!
• You need to be able to write Matlab code “OFFLINE”!So, improve your ability to write/understand Matlab codeWITHOUT using Matlab itself!
Good Bye
• Okay guys/gals, this is our last meeting for this semester.
• If we happen to bump into each other(perhaps at engineering canteen),do not forget to say hi .
• If I have said wrong things… please accept my apology…
• I hope that you have learned a lot from this course.
• Not just the technical stuffs, but also the other moral values like:
• Do not plagiarize.
• Submit on time, punctual during classes.