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

2 次查看(过去 30 天)
%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 ])

回答(1 个)

Walter Roberson
Walter Roberson 2022-9-23
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 个评论
MJ
MJ 2022-9-23
Thank you, however I already answered this question, and the incorrect code is only a capital letter.
Walter Roberson
Walter Roberson 2022-9-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by