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