Ma`ruza 9 Overview - In this lecture, we’ll look at some commands that are useful for working with data!
- fzero
- sum, min, max, length, mean, median, std, and sort
- polyval, polyfit, polyder, polyint
fzero - One of MATLAB’s built-in functions is “fzero”.
- fzero uses the Bisection Method to find a zero of a function f(x).
- Syntax: fzero(‘f’,x0) where f is a function defined in MATLAB and x0 is either a starting value or an interval of the form [x1 x2].
- In the second case, f(x1) and f(x2) must differ in sign.
fzero - Example 1: Try each of the following commands:
- fzero('cos',1.5)
- z1 = fzero('cos(x.^2)', [0 sqrt(pi)])
fzero - Example 2: Plot the function y=Sample1(x) on the interval [-2,2].
- Use the graph to pick a starting value x0 for fzero to locate the positive zero.
- Then try z2 = fzero('Sample1',x0).
- In MATLAB, the following should produce the same result:
- z3 = fzero('x+x.^2-x.^4',x0).
fzero - Example 3: Create an M-file called Example3.m with this script:
- x = -2:0.01:2;
- plot(x, Sample1(x));
- z = fzero('Sample1', [1 2]);
- title('The positive zero of y = x+x^2-x^4');
- grid on;
- set(gca, 'Xtick', [-2:1 z 2]);
- %This last command specifies tick-marks on the x-axis.
- %Note that tick marks must be specified in ascending or descending order.
- MATLAB has several functions that can be used to work with sets of data, including:
- sum, min, max, length, mean, median, std, and sort
- Use the Help file to learn more about each!
Working with Data - Example 4: Let x = [5 2 1 6 3]. Enter vector x and find each of the following:
- sum(x)
- min(x)
- [mx, indx] = min(x)
- max(x)
- [Mx, indx] = max(x)
- length(x)
- mean(x)
- sum(x)/length(x)
- std(x)
- sort(x)
Do'stlaringiz bilan baham: |