quadMin - if xc< L xMin= L xMax= R else xMin= R xMax= L...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% Script quadMin % Minimum and Maximum of a quadratic q(x) = x^2 + bx + c % [Use nested IFs] close all disp('Min and max of quadratic x^2 + bx + c over [L,R]') b = input('Enter b: '); c = input('Enter c: '); L = input('Enter L: '); R = input('Enter R (L<=R): '); xc = -b/2; % critical point % critical point is inside the interval xMin= xc; if (xc-L)>(R-xc) xMax= L; else xMax= R; end else % Minimum of q is at one of the endpoints
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if xc < L xMin= L; xMax= R; else xMin= R; xMax= L; end end qMin= xMin^2 + b*xMin + c; qMax= xMax^2 + b*xMax + c; fprintf('Min value is %.4f\n', qMin) fprintf('Max value is %.4f\n', qMax) % Plot a graph xvector= linspace(L, R, 100); qvector= xvector.^2 + b*xvector + c; plot(xvector,qvector, xMin,qMin,'o', xMax,qMax,'*') title('q(x) from x=L to x=R')...
View Full Document

This note was uploaded on 10/04/2011 for the course 1920 1920 at Cornell.

Ask a homework question - tutors are online