freqEq1Error(0) ans = 0 freqEq1Error(1) ans = 2.5574 freqEq1Error(2) ans = -0.1850 freqEq1Error(1.9) ans = -1.0271 freqEq1Error(2.1) ans = 0.3902 omegaVals=[0:10] omegaVals = Columns 1 through 8 0 1 2 3 4 5 6 7 Columns 9 through 11 8 9 10 omegaVals=[0:0.05:10] omegaVals = Columns 1 through 5 0 0.0500 0.1000 0.1500 0.2000 Columns 6 through 10 0.2500 0.3000 0.3500 0.4000 0.4500 Columns 11 through 15 0.5000 0.5500 0.6000 0.6500 0.7000 Columns 16 through 20 0.7500 0.8000 0.8500 0.9000 0.9500 Columns 21 through 25 1.0000 1.0500 1.1000 1.1500 1.2000 Columns 26 through 30 1.2500 1.3000 1.3500 1.4000 1.4500 Columns 31 through 35 1.5000 1.5500 1.6000 1.6500 1.7000 Columns 36 through 40 1.7500 1.8000 1.8500 1.9000 1.9500 Columns 41 through 45 2.0000 2.0500 2.1000 2.1500 2.2000 Columns 46 through 50 2.2500 2.3000 2.3500 2.4000 2.4500 Columns 51 through 55 2.5000 2.5500 2.6000 2.6500 2.7000 Columns 56 through 60 2.7500 2.8000 2.8500 2.9000 2.9500 Columns 61 through 65 3.0000 3.0500 3.1000 3.1500 3.2000 Columns 66 through 70 3.2500 3.3000 3.3500 3.4000 3.4500 Columns 71 through 75 3.5000 3.5500 3.6000 3.6500 3.7000 Columns 76 through 80 3.7500 3.8000 3.8500 3.9000 3.9500 Columns 81 through 85 4.0000 4.0500 4.1000 4.1500 4.2000 Columns 86 through 90 4.2500 4.3000 4.3500 4.4000 4.4500 Columns 91 through 95 4.5000 4.5500 4.6000 4.6500 4.7000 Columns 96 through 100 4.7500 4.8000 4.8500 4.9000 4.9500 Columns 101 through 105 5.0000 5.0500 5.1000 5.1500 5.2000 Columns 106 through 110 5.2500 5.3000 5.3500 5.4000 5.4500 Columns 111 through 115 5.5000 5.5500 5.6000 5.6500 5.7000 Columns 116 through 120 5.7500 5.8000 5.8500 5.9000 5.9500 Columns 121 through 125 6.0000 6.0500 6.1000 6.1500 6.2000 Columns 126 through 130 6.2500 6.3000 6.3500 6.4000 6.4500 Columns 131 through 135 6.5000 6.5500 6.6000 6.6500 6.7000 Columns 136 through 140 6.7500 6.8000 6.8500 6.9000 6.9500 Columns 141 through 145 7.0000 7.0500 7.1000 7.1500 7.2000 Columns 146 through 150 7.2500 7.3000 7.3500 7.4000 7.4500 Columns 151 through 155 7.5000 7.5500 7.6000 7.6500 7.7000 Columns 156 through 160 7.7500 7.8000 7.8500 7.9000 7.9500 Columns 161 through 165 8.0000 8.0500 8.1000 8.1500 8.2000 Columns 166 through 170 8.2500 8.3000 8.3500 8.4000 8.4500 Columns 171 through 175 8.5000 8.5500 8.6000 8.6500 8.7000 Columns 176 through 180 8.7500 8.8000 8.8500 8.9000 8.9500 Columns 181 through 185 9.0000 9.0500 9.1000 9.1500 9.2000 Columns 186 through 190 9.2500 9.3000 9.3500 9.4000 9.4500 Columns 191 through 195 9.5000 9.5500 9.6000 9.6500 9.7000 Columns 196 through 200 9.7500 9.8000 9.8500 9.9000 9.9500 Column 201 10.0000 errorVals=freqEq1Error(omegaVals) errorVals = Columns 1 through 5 0 0.1000 0.2003 0.3011 0.4027 Columns 6 through 10 0.5053 0.6093 0.7150 0.8228 0.9331 Columns 11 through 15 1.0463 1.1631 1.2841 1.4102 1.5423 Columns 16 through 20 1.6816 1.8296 1.9883 2.1602 2.3484 Columns 21 through 25 2.5574 2.7933 3.0648 3.3845 3.7722 Columns 26 through 30 4.2596 4.9021 5.8052 7.1979 9.6881 Columns 31 through 35 15.6014 49.6285 -32.6325 -10.9493 -5.9966 Columns 36 through 40 -3.7704 -2.4863 -1.6381 -1.0271 -0.5595 Columns 41 through 45 -0.1850 0.1254 0.3902 0.6210 0.8262 Columns 46 through 50 1.0114 1.1808 1.3375 1.4840 1.6220 Columns 51 through 55 1.7530 1.8781 1.9984 2.1146 2.2273 Columns 56 through 60 2.3371 2.4445 2.5499 2.6536 2.7560 Columns 61 through 65 2.8575 2.9582 3.0584 3.1584 3.2585 Columns 66 through 70 3.3588 3.4597 3.5615 3.6643 3.7686 Columns 71 through 75 3.8746 3.9827 4.0935 4.2073 4.3247 Columns 76 through 80 4.4466 4.5736 4.7068 4.8474 4.9971 Columns 81 through 85 5.1578 5.3321 5.5235 5.7366 5.9778 Columns 86 through 90 6.2563 6.5858 6.9876 7.4963 8.1733 Columns 91 through 95 9.1373 10.6538 13.4602 20.6577 85.4128 Columns 96 through 100 -21.8254 -6.5849 -2.3709 -0.3675 0.8209 Columns 101 through 105 1.6195 2.2014 2.6506 3.0126 3.3144 Columns 106 through 110 3.5727 3.7987 4.0002 4.1825 4.3495 Columns 111 through 115 4.5044 4.6493 4.7861 4.9160 5.0403 Columns 116 through 120 5.1598 5.2753 5.3875 5.4969 5.6039 Columns 121 through 125 5.7090 5.8125 5.9147 6.0160 6.1166 Columns 126 through 130 6.2168 6.3168 6.4169 6.5173 6.6184 Columns 131 through 135 6.7203 6.8233 6.9279 7.0342 7.1428 Columns 136 through 140 7.2540 7.3683 7.4865 7.6091 7.7371 Columns 141 through 145 7.8714 8.0135 8.1649 8.3277 8.5046 Columns 146 through 150 8.6993 8.9166 9.1633 9.4493 9.7892 Columns 151 through 155 10.2060 10.7377 11.4523 12.4842 14.1429 Columns 156 through 160 17.3324 26.3068 259.0018 -13.8151 -2.4326 Columns 161 through 165 1.2003 3.0139 4.1176 4.8711 5.4263 Columns 166 through 170 5.8583 6.2086 6.5021 6.7543 6.9757 Columns 171 through 175 7.1736 7.3531 7.5180 7.6710 7.8144 Columns 176 through 180 7.9499 8.0789 8.2023 8.3211 8.4360 Columns 181 through 185 8.5477 8.6566 8.7633 8.8681 8.9714 Columns 186 through 190 9.0734 9.1746 9.2751 9.3752 9.4752 Columns 191 through 195 9.5754 9.6759 9.7770 9.8791 9.9824 Columns 196 through 200 10.0872 10.1939 10.3029 10.4146 10.5295 Column 201 10.6484 errorVals=freqEq1Error(omegaVals); plot(omegaVals',errorVals') 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(omegaVals',errorVals','--or','LineWidth',2) plot(omegaVals',errorVals') axis([0 10 -10 10]) grid on set(gca) ALim: {} ALimMode: {'auto' 'manual'} ActivePositionProperty: {1×2 cell} 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: {1×2 cell} Color: {1×0 cell} ColorOrder: {} ColorOrderIndex: {} CreateFcn: {} DataAspectRatio: {} DataAspectRatioMode: {'auto' 'manual'} DeleteFcn: {} FontAngle: {'normal' 'italic'} FontName: {} FontSize: {} 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: {1×3 cell} 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: {1×3 cell} PlotBoxAspectRatio: {} PlotBoxAspectRatioMode: {'auto' 'manual'} Position: {} Projection: {1×2 cell} Selected: {'on' 'off'} SelectionHighlight: {'on' 'off'} SortMethod: {1×2 cell} Tag: {} TickDir: {'in' 'out' 'both'} TickDirMode: {'auto' 'manual'} TickLabelInterpreter: {1×3 cell} TickLength: {} Title: {} TitleFontSizeMultiplier: {} TitleFontWeight: {'normal' 'bold'} UIContextMenu: {} Units: {1×6 cell} UserData: {} View: {} Visible: {'on' 'off'} XAxis: {} XAxisLocation: {1×3 cell} 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: {1×3 cell} 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') xlabel('omega') ylabel('error (k=1)') title("Frequency Equation Error (k=1)') title("Frequency Equation Error (k=1)')  {Error: String is not terminated properly. } title('Frequency Equation Error (k=1)') 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 omega1=fzero('freqEq1Error',2) omega1 = 2.0288 omega1=fzero('freqEq1Error',0.5*pi) omega1 = 1.5708 omega1=fzero('freqEq1Error',[2 2.1]) omega1 = 2.0288 errorVals=freqEq1Error(omegaVals) errorVals = Columns 1 through 5 0 0.0999 0.1993 0.2978 0.3947 Columns 6 through 10 0.4896 0.5821 0.6717 0.7578 0.8402 Columns 11 through 15 0.9182 0.9916 1.0598 1.1226 1.1796 Columns 16 through 20 1.2304 1.2747 1.3123 1.3428 1.3660 Columns 21 through 25 1.3818 1.3899 1.3902 1.3825 1.3669 Columns 26 through 30 1.3431 1.3113 1.2714 1.2234 1.1674 Columns 31 through 35 1.1036 1.0320 0.9529 0.8663 0.7726 Columns 36 through 40 0.6721 0.5649 0.4514 0.3320 0.2071 Columns 41 through 45 0.0770 -0.0578 -0.1970 -0.3399 -0.4862 Columns 46 through 50 -0.6353 -0.7867 -0.9399 -1.0943 -1.2493 Columns 51 through 55 -1.4044 -1.5590 -1.7124 -1.8642 -2.0136 Columns 56 through 60 -2.1602 -2.3032 -2.4422 -2.5765 -2.7056 Columns 61 through 65 -2.8289 -2.9458 -3.0557 -3.1583 -3.2529 Columns 66 through 70 -3.3391 -3.4164 -3.4844 -3.5427 -3.5908 Columns 71 through 75 -3.6284 -3.6552 -3.6709 -3.6751 -3.6678 Columns 76 through 80 -3.6487 -3.6175 -3.5743 -3.5189 -3.4513 Columns 81 through 85 -3.3714 -3.2793 -3.1751 -3.0588 -2.9307 Columns 86 through 90 -2.7909 -2.6396 -2.4772 -2.3039 -2.1201 Columns 91 through 95 -1.9261 -1.7225 -1.5096 -1.2880 -1.0581 Columns 96 through 100 -0.8207 -0.5762 -0.3252 -0.0685 0.1932 Columns 101 through 105 0.4594 0.7292 1.0019 1.2767 1.5528 Columns 106 through 110 1.8295 2.1059 2.3812 2.6546 2.9252 Columns 111 through 115 3.1921 3.4547 3.7119 3.9630 4.2072 Columns 116 through 120 4.4436 4.6714 4.8899 5.0982 5.2957 Columns 121 through 125 5.4816 5.6552 5.8158 5.9627 6.0955 Columns 126 through 130 6.2134 6.3159 6.4026 6.4729 6.5265 Columns 131 through 135 6.5629 6.5819 6.5831 6.5662 6.5312 Columns 136 through 140 6.4778 6.4060 6.3157 6.2069 6.0798 Columns 141 through 145 5.9343 5.7707 5.5893 5.3902 5.1738 Columns 146 through 150 4.9405 4.6908 4.4251 4.1440 3.8480 Columns 151 through 155 3.5378 3.2140 2.8775 2.5289 2.1691 Columns 156 through 160 1.7990 1.4194 1.0312 0.6355 0.2332 Columns 161 through 165 -0.1746 -0.5870 -1.0028 -1.4210 -1.8403 Columns 166 through 170 -2.2598 -2.6783 -3.0945 -3.5074 -3.9158 Columns 171 through 175 -4.3186 -4.7146 -5.1026 -5.4815 -5.8503 Columns 176 through 180 -6.2077 -6.5527 -6.8843 -7.2014 -7.5029 Columns 181 through 185 -7.7881 -8.0558 -8.3052 -8.5354 -8.7457 Columns 186 through 190 -8.9352 -9.1032 -9.2492 -9.3723 -9.4722 Columns 191 through 195 -9.5483 -9.6001 -9.6273 -9.6296 -9.6067 Columns 196 through 200 -9.5584 -9.4847 -9.3854 -9.2605 -9.1103 Column 201 -8.9347 plot(omegaVals',errorVals') grid on set(gca,'xaxislocation','origin') xlabel('omega') ylabel('error (k=1)') title('Frequency Equation Error (k=1)') errorVals=freqEq1Error(omegaVals); omega1=fzero('freqEq1Error',[0.5*pi 1.5*pi]) omega1 = 2.0288 set(gca,'xtick',[0:pi:3*pi]) omega1=fzero('freqEq1Error',[0.5*pi 1.5*pi]) omega1 = 2.0288 omega2=fzero('freqEq1Error',[1.5*pi 2.5*pi]) omega2 = 4.9132 omega3=fzero('freqEq1Error',[2.5*pi 3.5*pi]) omega3 = 7.9787 omega4=fzero('freqEq1Error',[3.5*pi 4.5*pi]) omega4 = 11.0855 3.5*pi ans = 10.9956 omega4Interval=[3.5*pi 4.5*pi] omega4Interval = 10.9956 14.1372 omega4=fzero('freqEq1Error',omega4Interval) omega4 = 11.0855 omega1=fzero(@(omega) freqEq1Error(omega,k),[0.5*pi 1.5*pi]) {Error using fzero (line 246) FZERO cannot continue because user-supplied function_handle ==> @(omega)freqEq1Error(omega,k) failed with the error below. Undefined function or variable 'k'.} k=1 k = 1 omega1=fzero(@(omega) freqEqError(omega,k),[0.5*pi 1.5*pi]) omega1 = 2.0288 omega1=fzero(@(omega) freqEqError(omega,k),[0.5*pi 1.5*pi]) omega1 = 2.0288 fzero(@(omega) freqEqError(omega,k),[1.5*pi 2.5*pi]) ans = 4.9132 omega2=fzero(@(omega) freqEqError(omega,k),[1.5*pi 2.5*pi]) omega2 = 4.9132 k=2 k = 2 omega1=fzero(@(omega) freqEqError(omega,k),[0.5*pi 1.5*pi]) omega1 = 1.8366 fprintf('For k = %f, frequency %i equals: %f',k,1,omega1) For k = 2.000000, frequency 1 equals: 1.836597aaa {Undefined function or variable 'aaa'.} fprintf('For k = %f, frequency %i equals: %f\n',k,1,omega1) For k = 2.000000, frequency 1 equals: 1.836597 fprintf('For k = %4.2f, frequency %1i equals: %10.8f\n',k,1,omega1) For k = 2.00, frequency 1 equals: 1.83659720