Unrecognized function or variable 'CP'. Error in solution (line 66) text(c+.5,​f(c),["("+​string(c)+​","+string​(f(c))+") "+CP ])

11 views (last 30 days)
%Use symbolic processing with the variable x
syms x
%Enconde the function f(x)
num = (1-x^2)
denom = (1+x^2)
f(x) = num/denom
eqn = num/denom==0
cc1= solve(eqn)
%Set the distance to the left/right of the critical point
h=0.01
%Find the first derivative of the function
fp(x) = diff(f(x))
%Solve for the roots of fp
root1 = solve(fp)
%Consider the first critical point only
c=root1(1)
%Determine if the function is "Increasing" or "Decreasing" at the right of the critical point
if (fp(c+h)>0)
IoDR = "increasing"
elseif (fp(c+h)<0)
IoDR = "decreasing"
end
%Determine if the function is "Increasing" or "Decreasing" at the right of the critical point
if (fp(c-h)>0)
IoDL = "decreasing"
elseif (fp(c-h)<0)
IoDL ="increasing"
end
%Use first derivative Test to Determine if the critical point is a "Maximum" point or "Minimum" point.
if IoDL=="Increasing" & IoDR =="Decreasing"
CP= "Maximum"
elseif IoDL=="Decreasing" & IoDR =="Increasing"
CP= "Minimum"
end
%Find the second derivative of the function
fpp(x)= diff(f,2);
eqn1 = fpp==0
%Find the points of inflection of the function by equating the second derivative of the function to zero.
cc = solve(eqn1)
%Apply Second Derivative Test to check whether the critical point is a "Maximum" point, a "Minimum" point or "Point of Inflection".
if fpp(c) >0
CP2 = "Maximum"
elseif fpp(c)<0
CP2 = "Minimum"
else
CP2 = "Point of Inflection"
end
%GRAPH THE FUNCTION
clf();
g1= ezplot(f);
hold on
grid on
plot(c,f(c), 'r*')
title("Curve Tracing")
text(c+.5,f(c),["("+string(c)+","+string(f(c))+") "+CP ])
I'm still new to Matlab, Please assist me in resolving this issue at line 66. Thank you very lot.
Unrecognized function or variable 'CP'. Error in solution (line 66) text(c+.5,f(c),["("+string(c)+","+string(f(c))+") "+CP ])

Answers (1)

Walter Roberson
Walter Roberson on 23 Sep 2022
You have
if IoDL=="Increasing" & IoDR =="Decreasing"
CP= "Maximum"
elseif IoDL=="Decreasing" & IoDR =="Increasing"
CP= "Minimum"
end
but if both of them are increasing or both of them are decreasing then you do not assign anything to CP.
  2 Comments
Walter Roberson
Walter Roberson on 23 Sep 2022
Well that is difficult to verify now that the code is removed. From what I recall of the code, the issue I pointed out is also a problem.

Sign in to comment.

Categories

Find more on Coordinate Transformations and Trajectories in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by