Professional Documents
Culture Documents
String manipulation
Presenting Results
- All plots displayed though figure window: figure()
- Activate 3rd figure: figure(3)
Plots
- 2D plots: plot()
Lines and Symbol Types in Plotting
Functions
- function [out1, out2] = FUN (IN1, IN2)
- command function must be at the first line of code
- FUN is the name of the function (should equal to M- file name)
- Local variables: functions use this only while function is executing
- Global variables: share variables between functions
- Functions call other functions: function disp_my_plot
Relational operators
Logical operators
Logical functions
For Loop
for ii = 0:5
disp(ii);
a(ii+1) = ii;
end
While Loop
ii = 0;
while ii <= 5
disp(ii);
ii = ii + 1;
end
- advantage over for loop: loop counter is not going in one direction. We can have statements
within loops such as increase, decrease and reset counter.
If condition
if expression
statement
elseif expression
statement,
else
statement,
end
Break command
- used to terminate the execution of for and while loop
Lecture 3: Nonlinear equations, Bisection method, Fixed point
iteration, Newton- Raphson method, Secant method
Solving nonlinear equations
- solutions in the form of roots may be obtained from functions such as quadratic equation.
Iterative Methods
- solved by initial approximation and is improved using iterative methods
- successive use of iterative methods result in approximations which approach the solution,
Iterative method is then considered to be converged
- approximate error estimate is needed to detect is method and converged sufficiently
Useful Theorems
Initial Approximations
Note: initial approximations can be found by neglecting middle term
Graphical Method
- equate both equations, bring them all to one side to equal 0 and find x (roots)
- used to obtain rough estimate of roots