I can't find a way around these errors: "Unrecognized function or variable 'CP'" and "Error in solution (line 63) text(c+.5,​f(c),["("+​string(c)+​","+string​(f(c))+") "+CP ])"

4 views (last 30 days)
%Use symbolic processing with the variable x
syms x
%Enconde the function f(x)
f(x) = (1-x^2)/(1+x^2)
f(x) = 
%Set the distance to the left/right of the critical point
h=0.01
h = 0.0100
%Find the first derivative of the function
fp(x) = diff(f,1)
fp(x) = 
%Solve for the roots of fp
root1 = solve(fp)
root1 = 
0
%Consider the first critical point only
c=root1(1)
c = 
0
%Determine if the function is "Increasing" or "Decreasing" at the right of the critical point
if (fp(c+h)>0)
IoDR = "Decreasing"
elseif (fp(c+h)<0)
IoDR = "Increasing"
end
IoDR = "Increasing"
%Determine if the function is "Increasing" or "Decreasing" at the right of the critical point
if (fp(c-h)>0)
IoDL = "Increasing"
elseif (fp(c-h)<0)
IoDL = "Decreasing"
end
IoDL = "Increasing"
%Use first derivative Test to Determine if the critical point is a "Maximum" point or "Minimum" point.
if IoDL=="Increasing" & IoDR =="Decreasing"
CP(x)= "Minimum"
elseif IoDL=="Decreasing" & IoDR =="Increasing"
CP(x)= "Maximum"
end
%Find the second derivative of the function
fpp(x)= diff(f,2);
%Find the points of inflection of the function by equating the second derivative of the function to zero.
cc = (-sqrt(3)/3), (1/2)
cc = -0.5774
ans = 0.5000
(sqrt(3)/3), (1/2)
ans = 0.5774
ans = 0.5000
%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 = "Minimum"
elseif fpp(c)<0
CP2 = "Maximum"
else
CP2 = "Point of Inflection"
end
CP2 = "Maximum"
%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 ])
Unrecognized function or variable 'CP'.
Errors:
Unrecognized function or variable 'CP'.
Error in solution (line 63)
text(c+.5,f(c),["("+string(c)+","+string(f(c))+") "+CP ])

Answers (1)

Cris LaPierre
Cris LaPierre on 1 Apr 2023
Edited: Cris LaPierre on 1 Apr 2023
You are using a variable CP without ever defining it, hence the error.
  2 Comments
Cris LaPierre
Cris LaPierre on 1 Apr 2023
Edited: Cris LaPierre on 1 Apr 2023
It is not being assigned a value in your if statement because neither condition is true.
if IoDL=="Increasing" & IoDR =="Decreasing"
CP(x)= "Minimum"
elseif IoDL=="Decreasing" & IoDR =="Increasing"
CP(x)= "Maximum"
end
A quick inspection of the code determining slope (IoDL & IoDR) shows there is a logic error in your definition of IoDR. Should a positive slope be labeled "Decreasing"?
if (fp(c+h)>0)
IoDR = "Decreasing"
elseif (fp(c+h)<0)
IoDR = "Increasing"
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!