Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course page: http://www.cse.yorku.ca/course/1560 CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011 Suprakash Datta.

Similar presentations


Presentation on theme: "Course page: http://www.cse.yorku.ca/course/1560 CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011 Suprakash Datta."— Presentation transcript:

1 Course page: http://www.cse.yorku.ca/course/1560
CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011 Suprakash Datta Office: CSEB 3043 Phone: ext 77875 Course page: 8/14/2019 Math/CSE 1560, Winter 2011 1

2 Announcements This week’s lab will also be a lightweight one.
You will work individually. You can finish lab 1 without penalty. After this week, 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. 8/14/2019 Math/CSE 1560, Winter 2011

3 Last class Basic Maple commands and syntax Today:
Some programming principles More about solving equations and Plotting graphs. 8/14/2019 Math/CSE 1560, Winter 2011

4 Programming principles
Programs have to be readable, for Debugging Extending functionality Maintenance Evaluation Programming style includes directions for creating code that is easier to read. Typical software companies spend much more effort debugging and maintaining software than in developing it. 8/14/2019 Math/CSE 1560, Winter 2011

5 Programming principle 1
Variable names Good mnemonic value Low ambiguity Examples: Bad names: i,j,x,y Better names: iter_num, current_value, x_squared 8/14/2019 Math/CSE 1560, Winter 2011

6 Programming principle 2
Comments (“documentation”) Meant to help the reader understand code Tradeoff between verbosity and readability Reader should not have to spend hours trying to figure out what the programmer wants to do Use to describe the problem being solved Overall idea of the solution Idea behind each major piece Any segment that may not be obvious 8/14/2019 Math/CSE 1560, Winter 2011

7 Verbosity vs readability
Bad example: x:=x+1; # add one to the current value of x Better example: #find the number of zeroes in n!, n<=100 8/14/2019 Math/CSE 1560, Winter 2011

8 A middle school problem
Q: How many zeroes are there at the end of 100! 8/14/2019 Math/CSE 1560, Winter 2011

9 Plotting graphs Basic command: >plot(func,x=a..b);
E.g. plot(x^2,x=0..3); 8/14/2019 Math/CSE 1560, Winter 2011

10 Multiple graphs > plot([func1,func2,func3],x=a..b); Example:
plot([3*x^4-5*x,10*sin(x)-10,5*cos(x)+3*exp(x)],x=-2..2); What’s missing? 8/14/2019 Math/CSE 1560, Winter 2011

11 A better plot > plot(15+cos(x),x=0..4*Pi,labels = [“day”,”price”],title = “Daily price of Maple syrup”); 8/14/2019 Math/CSE 1560, Winter 2011

12 More plot options color=“Red” thickness = 3 More at ?plot[options]
8/14/2019 Math/CSE 1560, Winter 2011

13 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)); 8/14/2019 Math/CSE 1560, Winter 2011

14 More on solving equations - 2
> solve(x^2-2 = 0,x); Simplify: > evalf(%) ; BUT > simplify(%) does not work! 8/14/2019 Math/CSE 1560, Winter 2011

15 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); , *I, *I, *I, *I 8/14/2019 Math/CSE 1560, Winter 2011

16 More on solving equations - 4
In general use fsolve for numerical solutions. fsolve(x^5-x^3=1,x); 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]; 8/14/2019 Math/CSE 1560, Winter 2011

17 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); > fsolve(exp(x^2)-50*x^2+3*x = 0, x); 8/14/2019 Math/CSE 1560, Winter 2011

18 Solutions within a range
> fsolve(sin(x)-x=0,x,-Pi..Pi); Can do the same for solving several equations simultaneously. 8/14/2019 Math/CSE 1560, Winter 2011


Download ppt "Course page: http://www.cse.yorku.ca/course/1560 CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011 Suprakash Datta."

Similar presentations


Ads by Google