140 likes | 148 Views
This course provides an introduction to computing principles and techniques for mathematics and statistics students. Topics include programming, plotting graphs, solving equations, and writing functions.
E N D
Suprakash Datta datta@cse.yorku.ca Office: CSEB 3043 Phone: 416-736-2100 ext 77875 Course page: http://www.cse.yorku.ca/course/1560 CSE/Math 1560:Introduction to Computing for Mathematics and Statistics Winter 2011 Math/CSE 1560, Winter 2011
Math/CSE 1560, Winter 2011 Announcements This week’s lab will not be graded. You will work individually. You can finish lab 1 without penalty next week. Thereafter, you will have to finish each lab within the lab hours. It is your responsibility to know which lab section you are enrolled in and show up at the correct time.
Math/CSE 1560, Winter 2011 Last class 1. Some programming principles and • 2. Plotting graphs. • Next: Solving equations, writing your own functions.
Math/CSE 1560, Winter 2011 A better plot > plot(15+cos(x),x=0..4*Pi,labels = [“day”,”price”],title = “Daily price of Maple syrup”);
Math/CSE 1560, Winter 2011 More plot options • color=“Red” • thickness = 3 • More at ?plot[options]
Math/CSE 1560, Winter 2011 More on solving equations > solve(3*x+2 = 11,x); Check your answer: > eval(3*x+2,x=3) OR > evalb(eval(3*x+2=11,x=3));
Math/CSE 1560, Winter 2011 More on solving equations - 2 > solve(x^2-2 = 0,x); Simplify: > evalf(%) ; BUT > simplify(%) does not work!
Math/CSE 1560, Winter 2011 More on solving equations - 3 > solve({3*x-2*y = 0,4*x+5*y=10},{x,y}); Simplify: > evalf(%) ; Notice: solve(x^5-x^3=1,x); RootOf(_Z^5-_Z^3-1, index = 1), RootOf(_Z^5-_Z^3-1, index = 2), RootOf(_Z^5-_Z^3-1, index = 3), RootOf(_Z^5-_Z^3-1, index = 4), RootOf(_Z^5-_Z^3-1, index = 5) solve(x^5-x^3=1.0,x); 1.236505703, .3407948662+.7854231030*I, -.9590477179+.4283659562*I, -.9590477179-.4283659562*I, .3407948662-.7854231030*I
Math/CSE 1560, Winter 2011 More on solving equations - 4 In general use fsolve for numerical solutions. fsolve(x^5-x^3=1,x); 1.236505703 fsolve(x^5-x^3=1,x,complex,maxsols=5); To access individual solutions: Sols:= fsolve(x^5-x^3=1,x,complex,maxsols=5); Sols[3];
Math/CSE 1560, Winter 2011 Steps for solving equations • > solve(exp(x^2)-50*x^2+3*x = 0, x); • Warning, solutions may have been lost • > solve(exp(x^2)-50*x^2+3*x = 0., x); • Warning, solutions may have been lost • > fsolve(exp(x^2)-50*x^2+3*x = 0, x); • -0.1154942111
Math/CSE 1560, Winter 2011 Solutions within a range > fsolve(sin(x)-x=0,x,-Pi..Pi); Can do the same for solving several equations simultaneously.
Math/CSE 1560, Winter 2011 Programming principle • Modular development • Reasons: • Code re-use • Develop, debug in isolation • Divide complex task into manageable pieces • A change in this module can be made without any other changes in other parts of the program.
Math/CSE 1560, Winter 2011 Simple functions • f:= x->x^2+x+1; • Try f(2),f(x+1),f(f(x)) • f:= (x,y)->x^2+y^2;
Math/CSE 1560, Winter 2011 A piecewise defined function • Math: • H(x) = 1, if x>0 • = 0 if x <=0 • Maple: • h:= x->piecewise(x>0,1,x<=0,0);