Excel Definitions


Download 479.24 Kb.
bet1/4
Sana04.04.2023
Hajmi479.24 Kb.
#1326569
  1   2   3   4
Bog'liq
8-lecture

Ma`ruza 9

Matlabda ma`lumotlar bilan ishlash

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)])
    • For Octave, to use this command, create a function M-file for cos(x.^2), such as “Sample2.m”.

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.

Working with Data

  • 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)

Download 479.24 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling