function polyegsimple % Cubic Polynomial Simple Example: y = f(x) = x^3+x^2-3*x-3; clc % MATLAB Zero Finding Function "fzero" for m-file subfunction f % near a point (here 2): [xs,fs] = fzero(@f,2); % Note: for non-inline function, % function argument needs a function handle "@". fprintf('\n f(x) roots near x=2: xs = %f; f(xs) = %e;',xs,fs); fprintf('\n POOR MATLAB Unlabeled Output:'); fzero(@f,2) % % MATLAB Polynomial Root Finder Function "root": r = roots([1,1,-3,-3]); % Uses polynomial coeffs, % from highest to lowest degree in row vector form. fprintf('\n Polynomial Roots of f(x):\n r =[%f; %f; %f;]'); fprintf('%f; ',r); % Prints roots vector by reusing format. % % Polynomial Plot with vectors (x,y): x = -3:0.1:+3; y = f(x); plot(x,y); xlabel('x'); ylabel('y'); title('MATLAB Plot of x^3+x^2-3*x-3'); grid on % function y=f(x) % Class Polynomial Example in Vector Compatible Format: y=x.^3+x.^2-3*x-3;