Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I write a for loop to classify every critical point? function [ output ] = ClassifyCP(f, var1, var2, xcp, ycp) % CLASSIFYCP is

image text in transcribed

How do I write a for loop to classify every critical point?

function [ output ] = ClassifyCP(f, var1, var2, xcp, ycp) % CLASSIFYCP is a function that can determine % if a critical point is a local maximum % Example use and output: %>> ClassifyCP('-(x^2-1)^2-(x^2*y-x-1)^2','x', 'y',-1,0) % % ans = % % The critical point (x,y)=(-1,0) is a local maximum var1 = sym(var1); var2 = sym(var2); f = evalin(symengine,f);

% Calculate the first and second order partial derivatives fx = diff(f,var1); fy = diff(f,var2); fxx = diff(fx, var1); fxy = diff(fx, var2); fyy = diff(fy, var2);

% Calculate Discriminant and 2nd order partials by % subbing in critical point with subs() D = fxx*fyy - fxy^2; D = simplify(D); Dval = subs(D, [var1,var2], [0,0]); fxxval = subs(fxx, [var1,var2], [0,0]); fyyval = subs(fyy, [var1,var2], [0,0]);

% Classify the critical point if Dval > 0 && fxxval 0 && fxxval > 0 classtext= ['a local minimum']; elseif Dval

output = ['The critical point (x,y)=(',... num2str(xcp),',',num2str(ycp),') is ',classtext];

Show/hide hint When you classify each successive critical point you need to move down the rows of cp. How would you index the x and y coordinates of the successive critical points stored in cp? To help you work this out you could try the commands out with the index variable k replaced with a specific value that would correspond to one of the rows. S = S = classifyCP('x*y*exp(-x^2- y^2)','x','y', cp(2,k), cp(1,k)) ClassifyCP('x*y*exp(-x^2- y^2)','x','y', cp(k,2), cp(k,1)) ClassifyCP('x*y*exp(-x^2- y^2)','x','y', cp(k,1), cp (k, 2)) s = ClassifyCP('x*y*exp(-x^2- y^2)','x', 'y', cp(1,k), cp(2, k)) Saved. S = This is the command that will be repeatedly executed inside the for loop. Write a for loop to classify every critical point stored in cp. You will need to come up with an appropriate index vector - do this without explicitly specifying the number of rows in cp. Copy your finished for loop commands and paste them in the following text box: Show/hide hint The index vector of the for loop should include every integer from 1 through to the number of rows of cp. To determine the number of rows or columns of a vector X you may recall that we use the size function with the syntax size(X, DIM). Type help size in the Command Window for more information on the use of the size function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

what does the School Safety MSD Act in FL say about cyber safety

Answered: 1 week ago

Question

3. How has Starbucks changed since its early days?

Answered: 1 week ago