My error says "Unrecognized function or variable 'CP'." What can I add to the script so that I can define it?
조회 수: 2 (최근 30일)
이전 댓글 표시
%Use symbolic processing with the variable x
syms x
%Enconde the function f(x)
f(x) = (1-x^2)/(1+x^2)
%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,1);
%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 = "Decreasing"
elseif (fp(c+h)<0)
IoDR = "Increasing"
end
%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
%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)
(sqrt(3)/3), (1/2)
%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
%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 ])
댓글 수: 0
답변 (1개)
VBBV
2023년 4월 1일
편집: VBBV
2023년 4월 1일
None of the if statements for variables IoDR, IoDL are being executed. Can you check if the preceding if conditions for variable fp are correct ? As you can see below, IoDR & IoDLare both "increasing", which makes the variable CP undefined
%Use symbolic processing with the variable x
syms x
%Enconde the function f(x)
f(x) = (1-x^2)/(1+x^2)
%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,1);
%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 = "Decreasing"
elseif (fp(c+h)<0)
IoDR = "Increasing"
end
%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
%Use first derivative Test to Determine if the critical point is a "Maximum" point or "Minimum" point.
if IoDL=="Increasing" & IoDR =="Increasing"
CP = "Minimum"
elseif IoDL=="Decreasing" & IoDR =="Decreasing"
CP = "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)
(sqrt(3)/3), (1/2)
%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
%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 ])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!