format compact
more off
error0=freqEqError1(0)
errorEq =
0
error0 =
0
error0=freqEqError1(0)
error0 =
0
error1=freqEqError1(1)
error1 =
1.3818
freqEqError1(2)
ans =
0.0770
error2=freqEqError1(2)
error2 =
0.0770
error1p9=freqEqError1(1.9)
error1p9 =
0.3320
error1p9=freqEqError1(2.1)
error1p9 =
-0.1970
omegaPlot=[0:0.1:12]
omegaPlot =
Columns 1 through 5
0 0.1000 0.2000 0.3000 0.4000
Columns 6 through 10
0.5000 0.6000 0.7000 0.8000 0.9000
Columns 11 through 15
1.0000 1.1000 1.2000 1.3000 1.4000
Columns 16 through 20
1.5000 1.6000 1.7000 1.8000 1.9000
Columns 21 through 25
2.0000 2.1000 2.2000 2.3000 2.4000
Columns 26 through 30
2.5000 2.6000 2.7000 2.8000 2.9000
Columns 31 through 35
3.0000 3.1000 3.2000 3.3000 3.4000
Columns 36 through 40
3.5000 3.6000 3.7000 3.8000 3.9000
Columns 41 through 45
4.0000 4.1000 4.2000 4.3000 4.4000
Columns 46 through 50
4.5000 4.6000 4.7000 4.8000 4.9000
Columns 51 through 55
5.0000 5.1000 5.2000 5.3000 5.4000
Columns 56 through 60
5.5000 5.6000 5.7000 5.8000 5.9000
Columns 61 through 65
6.0000 6.1000 6.2000 6.3000 6.4000
Columns 66 through 70
6.5000 6.6000 6.7000 6.8000 6.9000
Columns 71 through 75
7.0000 7.1000 7.2000 7.3000 7.4000
Columns 76 through 80
7.5000 7.6000 7.7000 7.8000 7.9000
Columns 81 through 85
8.0000 8.1000 8.2000 8.3000 8.4000
Columns 86 through 90
8.5000 8.6000 8.7000 8.8000 8.9000
Columns 91 through 95
9.0000 9.1000 9.2000 9.3000 9.4000
Columns 96 through 100
9.5000 9.6000 9.7000 9.8000 9.9000
Columns 101 through 105
10.0000 10.1000 10.2000 10.3000 10.4000
Columns 106 through 110
10.5000 10.6000 10.7000 10.8000 10.9000
Columns 111 through 115
11.0000 11.1000 11.2000 11.3000 11.4000
Columns 116 through 120
11.5000 11.6000 11.7000 11.8000 11.9000
Column 121
12.0000
omegaPlot=[0:0.1:12];
errorPlot=errorEq(omegaPlot)
{Undefined function or variable 'errorEq'.}
errorPlot=freqEqError1(omegaPlot)
errorPlot =
Columns 1 through 5
0 0.1993 0.3947 0.5821 0.7578
Columns 6 through 10
0.9182 1.0598 1.1796 1.2747 1.3428
Columns 11 through 15
1.3818 1.3902 1.3669 1.3113 1.2234
Columns 16 through 20
1.1036 0.9529 0.7726 0.5649 0.3320
Columns 21 through 25
0.0770 -0.1970 -0.4862 -0.7867 -1.0943
Columns 26 through 30
-1.4044 -1.7124 -2.0136 -2.3032 -2.5765
Columns 31 through 35
-2.8289 -3.0557 -3.2529 -3.4164 -3.5427
Columns 36 through 40
-3.6284 -3.6709 -3.6678 -3.6175 -3.5189
Columns 41 through 45
-3.3714 -3.1751 -2.9307 -2.6396 -2.3039
Columns 46 through 50
-1.9261 -1.5096 -1.0581 -0.5762 -0.0685
Columns 51 through 55
0.4594 1.0019 1.5528 2.1059 2.6546
Columns 56 through 60
3.1921 3.7119 4.2072 4.6714 5.0982
Columns 61 through 65
5.4816 5.8158 6.0955 6.3159 6.4729
Columns 66 through 70
6.5629 6.5831 6.5312 6.4060 6.2069
Columns 71 through 75
5.9343 5.5893 5.1738 4.6908 4.1440
Columns 76 through 80
3.5378 2.8775 2.1691 1.4194 0.6355
Columns 81 through 85
-0.1746 -1.0028 -1.8403 -2.6783 -3.5074
Columns 86 through 90
-4.3186 -5.1026 -5.8503 -6.5527 -7.2014
Columns 91 through 95
-7.7881 -8.3052 -8.7457 -9.1032 -9.3723
Columns 96 through 100
-9.5483 -9.6273 -9.6067 -9.4847 -9.2605
Columns 101 through 105
-8.9347 -8.5088 -7.9854 -7.3682 -6.6621
Columns 106 through 110
-5.8728 -5.0074 -4.0734 -3.0797 -2.0356
Columns 111 through 115
-0.9513 0.1625 1.2945 2.4331 3.5665
Columns 116 through 120
4.6826 5.7693 6.8149 7.8076 8.7361
Column 121
9.5897
omegaPlot=[0:0.1:12];
errorPlot=freqEqError1(omegaPlot);
plot(omegaPlot,errorPlot)
help plot
plot Linear plot.
plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, disconnected
line objects are created and plotted as discrete points vertically at
X.
plot(Y) plots the columns of Y versus their index.
If Y is complex, plot(Y) is equivalent to plot(real(Y),imag(Y)).
In all other uses of plot, the imaginary part is ignored.
Various line types, plot symbols and colors may be obtained with
plot(X,Y,S) where S is a character string made from one element
from any or all the following 3 columns:
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
For example, plot(X,Y,'c+:') plots a cyan dotted line with a plus
at each data point; plot(X,Y,'bd') plots blue diamond at each data
point but does not draw any line.
plot(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by
the (X,Y,S) triples, where the X's and Y's are vectors or matrices
and the S's are strings.
For example, plot(X,Y,'y-',X,Y,'go') plots the data twice, with a
solid yellow line interpolating green circles at the data points.
The plot command, if no color is specified, makes automatic use of
the colors specified by the axes ColorOrder property. By default,
plot cycles through the colors in the ColorOrder property. For
monochrome systems, plot cycles over the axes LineStyleOrder property.
Note that RGB colors in the ColorOrder property may differ from
similarly-named colors in the (X,Y,S) triples. For example, the
second axes ColorOrder property is medium green with RGB [0 .5 0],
while plot(X,Y,'g') plots a green line with RGB [0 1 0].
If you do not specify a marker type, plot uses no marker.
If you do not specify a line style, plot uses a solid line.
plot(AX,...) plots into the axes with handle AX.
plot returns a column vector of handles to lineseries objects, one
handle per plotted line.
The X,Y pairs, or X,Y,S triples, can be followed by
parameter/value pairs to specify additional properties
of the lines. For example, plot(X,Y,'LineWidth',2,'Color',[.6 0 0])
will create a plot with a dark red line width of 2 points.
Example
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
See also plottools, semilogx, semilogy, loglog, plotyy, plot3, grid,
title, xlabel, ylabel, axis, axes, hold, legend, subplot, scatter.
Reference page for plot
Other functions named plot
plot(omegaPlot,errorPlot,':or')
plot(omegaPlot,errorPlot,':or','LineWidth',2)
plot(omegaPlot,errorPlot)
axis([0 12 -10 7])
grid on
plot(omegaPlot,errorPlot)
axis([0 12 -10 7])
grid on
set(gca)
ALim: {}
ALimMode: {'auto' 'manual'}
ActivePositionProperty: {1×2 cell}
AlphaScale: {'linear' 'log'}
Alphamap: {}
AmbientLightColor: {1×0 cell}
Box: {'on' 'off'}
BoxStyle: {'full' 'back'}
BusyAction: {'queue' 'cancel'}
ButtonDownFcn: {}
CLim: {}
CLimMode: {'auto' 'manual'}
CameraPosition: {}
CameraPositionMode: {'auto' 'manual'}
CameraTarget: {}
CameraTargetMode: {'auto' 'manual'}
CameraUpVector: {}
CameraUpVectorMode: {'auto' 'manual'}
CameraViewAngle: {}
CameraViewAngleMode: {'auto' 'manual'}
Children: {}
Clipping: {'on' 'off'}
ClippingStyle: {'rectangle' '3dbox'}
Color: {1×0 cell}
ColorOrder: {}
ColorOrderIndex: {}
ColorScale: {'linear' 'log'}
Colormap: {}
CreateFcn: {}
DataAspectRatio: {}
DataAspectRatioMode: {'auto' 'manual'}
DeleteFcn: {}
FontAngle: {'normal' 'italic'}
FontName: {}
FontSize: {}
FontSizeMode: {'auto' 'manual'}
FontSmoothing: {'on' 'off'}
FontUnits: {1×5 cell}
FontWeight: {'normal' 'bold'}
GridAlpha: {}
GridAlphaMode: {'auto' 'manual'}
GridColor: {1×0 cell}
GridColorMode: {'auto' 'manual'}
GridLineStyle: {1×5 cell}
HandleVisibility: {'on' 'callback' 'off'}
HitTest: {'on' 'off'}
Interruptible: {'on' 'off'}
LabelFontSizeMultiplier: {}
Layer: {'bottom' 'top'}
LineStyleOrder: {}
LineStyleOrderIndex: {}
LineWidth: {}
MinorGridAlpha: {}
MinorGridAlphaMode: {'auto' 'manual'}
MinorGridColor: {1×0 cell}
MinorGridColorMode: {'auto' 'manual'}
MinorGridLineStyle: {1×5 cell}
NextPlot: {1×4 cell}
OuterPosition: {}
Parent: {}
PickableParts: {'visible' 'none' 'all'}
PlotBoxAspectRatio: {}
PlotBoxAspectRatioMode: {'auto' 'manual'}
Position: {}
Projection: {1×2 cell}
Selected: {'on' 'off'}
SelectionHighlight: {'on' 'off'}
SortMethod: {'depth' 'childorder'}
Tag: {}
TickDir: {'in' 'out' 'both'}
TickDirMode: {'auto' 'manual'}
TickLabelInterpreter: {'none' 'tex' 'latex'}
TickLength: {}
Title: {}
TitleFontSizeMultiplier: {}
TitleFontWeight: {'normal' 'bold'}
Toolbar: {}
UIContextMenu: {}
Units: {1×6 cell}
UserData: {}
View: {}
Visible: {'on' 'off'}
XAxis: {}
XAxisLocation: {'bottom' 'top' 'origin'}
XColor: {1×0 cell}
XColorMode: {'auto' 'manual'}
XDir: {'normal' 'reverse'}
XGrid: {'on' 'off'}
XLabel: {}
XLim: {}
XLimMode: {'auto' 'manual'}
XMinorGrid: {'on' 'off'}
XMinorTick: {'on' 'off'}
XScale: {'linear' 'log'}
XTick: {}
XTickLabel: {}
XTickLabelMode: {'auto' 'manual'}
XTickLabelRotation: {}
XTickMode: {'auto' 'manual'}
YAxisLocation: {'left' 'right' 'origin'}
YColor: {1×0 cell}
YColorMode: {'auto' 'manual'}
YDir: {'normal' 'reverse'}
YGrid: {'on' 'off'}
YLabel: {}
YLim: {}
YLimMode: {'auto' 'manual'}
YMinorGrid: {'on' 'off'}
YMinorTick: {'on' 'off'}
YScale: {'linear' 'log'}
YTick: {}
YTickLabel: {}
YTickLabelMode: {'auto' 'manual'}
YTickLabelRotation: {}
YTickMode: {'auto' 'manual'}
ZAxis: {}
ZColor: {1×0 cell}
ZColorMode: {'auto' 'manual'}
ZDir: {'normal' 'reverse'}
ZGrid: {'on' 'off'}
ZLabel: {}
ZLim: {}
ZLimMode: {'auto' 'manual'}
ZMinorGrid: {'on' 'off'}
ZMinorTick: {'on' 'off'}
ZScale: {'linear' 'log'}
ZTick: {}
ZTickLabel: {}
ZTickLabelMode: {'auto' 'manual'}
ZTickLabelRotation: {}
ZTickMode: {'auto' 'manual'}
set(gca,'xaxislocation','origin')
help fzero
fzero Single-variable nonlinear zero finding.
X = fzero(FUN,X0) tries to find a zero of the function FUN near X0,
if X0 is a scalar. It first finds an interval containing X0 where the
function values of the interval endpoints differ in sign, then searches
that interval for a zero. FUN is a function handle. FUN accepts real
scalar input X and returns a real scalar function value F, evaluated
at X. The value X returned by fzero is near a point where FUN changes
sign (if FUN is continuous), or NaN if the search fails.
X = fzero(FUN,X0), where X0 is a vector of length 2, assumes X0 is a
finite interval where the sign of FUN(X0(1)) differs from the sign of
FUN(X0(2)). An error occurs if this is not true. Calling fzero with a
finite interval guarantees fzero will return a value near a point where
FUN changes sign.
X = fzero(FUN,X0), where X0 is a scalar value, uses X0 as a starting
guess. fzero looks for an interval containing a sign change for FUN and
containing X0. If no such interval is found, NaN is returned.
In this case, the search terminates when the search interval
is expanded until an Inf, NaN, or complex value is found. Note: if
the option FunValCheck is 'on', then an error will occur if an NaN or
complex value is found.
X = fzero(FUN,X0,OPTIONS) solves the equation with the default optimization
parameters replaced by values in the structure OPTIONS, an argument
created with the OPTIMSET function. See OPTIMSET for details. Used
options are Display, TolX, FunValCheck, OutputFcn, and PlotFcns.
X = fzero(PROBLEM) finds the zero of a function defined in PROBLEM.
PROBLEM is a structure with the function FUN in PROBLEM.objective,
the start point in PROBLEM.x0, the options structure in PROBLEM.options,
and solver name 'fzero' in PROBLEM.solver.
[X,FVAL]= fzero(FUN,...) returns the value of the function described
in FUN, at X.
[X,FVAL,EXITFLAG] = fzero(...) returns an EXITFLAG that describes the
exit condition. Possible values of EXITFLAG and the corresponding exit
conditions are
1 fzero found a zero X.
-1 Algorithm terminated by output function.
-3 NaN or Inf function value encountered during search for an interval
containing a sign change.
-4 Complex function value encountered during search for an interval
containing a sign change.
-5 fzero may have converged to a singular point.
-6 fzero can not detect a change in sign of the function.
[X,FVAL,EXITFLAG,OUTPUT] = fzero(...) returns a structure OUTPUT
with the number of function evaluations in OUTPUT.funcCount, the
algorithm name in OUTPUT.algorithm, the number of iterations to
find an interval (if needed) in OUTPUT.intervaliterations, the
number of zero-finding iterations in OUTPUT.iterations, and the
exit message in OUTPUT.message.
Examples
FUN can be specified using @:
X = fzero(@sin,3)
returns pi.
X = fzero(@sin,3,optimset('Display','iter'))
returns pi, uses the default tolerance and displays iteration information.
FUN can be an anonymous function:
X = fzero(@(x) sin(3*x),2)
FUN can be a parameterized function. Use an anonymous function to
capture the problem-dependent parameters:
myfun = @(x,c) cos(c*x); % The parameterized function.
c = 2; % The parameter.
X = fzero(@(x) myfun(x,c),0.1)
Limitations
X = fzero(@(x) abs(x)+1, 1)
returns NaN since this function does not change sign anywhere on the
real axis (and does not have a zero as well).
X = fzero(@tan,2)
returns X near 1.5708 because the discontinuity of this function near the
point X gives the appearance (numerically) that the function changes sign at X.
See also roots, fminbnd, function_handle.
Reference page for fzero
fzero(@freqEqError1,2)
{Error using fzero (line 306)
FZERO cannot continue because user-supplied
function_handle ==> freqEqError1 failed with the error
below.
Undefined function 'freqEqError1' for input arguments
of type 'double'.}
fzero(@FreqEqError1,2)
{Error using fzero (line 306)
FZERO cannot continue because user-supplied
function_handle ==> FreqEqError1 failed with the error
below.
Undefined function 'FreqEqError1' for input arguments
of type 'double'.}
fzero(@freqEqError1,2)
{Error using fzero (line 306)
FZERO cannot continue because user-supplied
function_handle ==> freqEqError1 failed with the error
below.
Undefined function 'freqEqError1' for input arguments
of type 'double'.}
fzero(@freqEqError1,2)
ans =
2.0288
format long
fzero(@freqEqError1,2)
ans =
2.028757838110434
fzero(@freqEqError1,5)
ans =
4.913180439434884
fzero(@freqEqError1,8)
ans =
7.978665712413241
fzero(@freqEqError1,11)
ans =
11.085538406497022
omegaRange1=[2 2.1]
omegaRange1 =
2.000000000000000 2.100000000000000
omega1=fzero(@freqEqError1,omegaRange1)
omega1 =
2.028757838110434
fzero(@freqEqError1,2)
ans =
2.028757838110434
% anonymous functions
fzero((omega) freqEqError(
fzero((omega) freqEqError(
{Error: Invalid expression. Check for missing
multiplication operator, missing or unbalanced
delimiters, or other syntax error. To construct
matrices, use brackets instead of parentheses.
}
k=1
k =
1
fzero(@(omega) freqEqError(omega,k),[2 2.1])
ans =
2.028757838110434
fzero(@freqEqError(omega,k),[2 2.1])
fzero(@freqEqError(omega,k),[2 2.1])
{Error: Invalid expression. When calling a function or
indexing a variable, use parentheses. Otherwise, check
for mismatched delimiters.
}
fzero(@(omega) freqEqError(omega,k),[2 2.1])
ans =
2.028757838110434
% fprintf('FORMATSTRING', number1, number2, number)
fprintf('for k=%f, omega%i equals: %f',k,1,omega1)
for k=1.000000, omega1 equals: 2.028758
fprintf('for k=%f, omega%i equals: %f\n',k,1,omega1)
for k=1.000000, omega1 equals: 2.028758
fprintf('for k=%.0f, omega%i equals: %f\n',k,1,omega1)
for k=1, omega1 equals: 2.028758
fprintf('for k=%.0f, omega%i equals: %f.2\n',k,1,omega1)
for k=1, omega1 equals: 2.028758.2
k=2
k =
2
omega1=fzero(@(omega) freqEqError(omega,k),2)
omega1 =
1.836597203152126
omega2=fzero(@(omega) freqEqError(omega,k),5)
omega2 =
4.815842317845935
omega3=fzero(@(omega) freqEqError(omega,k),8)
omega3 =
7.917052684666206
omega4=fzero(@(omega) freqEqError(omega,k),11)
omega4 =
11.040829817971295
fprintf('for k=%.0f, omega%i equals: %f.2\n',k,1,omega1)
for k=2, omega1 equals: 1.836597.2
fprintf('for k=%.0f, omega%i equals: %.2f\n',k,1,omega1)
for k=2, omega1 equals: 1.84
fprintf('for k=%.0f, omega%i equals: %.2f\n',k,4,omega4)
for k=2, omega4 equals: 11.04
fprintf('for k=%.0f, omega%i equals: %5.2f\n',k,4,omega4)
for k=2, omega4 equals: 11.04
fprintf('for k=%.0f, omega%i equals: %5.2f\n',k,1,omega1)
for k=2, omega1 equals: 1.84
pr
for k=2, omega1 equals: 1.84
for k=2, omega2 equals: 4.82
for k=2, omega3 equals: 7.92
for k=2, omega4 equals: 11.04