Can Someone help me solve what is wrong with this code

1 visualización (últimos 30 días)
Echo Lei
Echo Lei el 4 de Oct. de 2022
Comentada: VBBV el 6 de Oct. de 2022
%Use symbolic processing with the variable x
syms x
syms fp(x)
syms Increasing
syms Decreasing
syms Minimum
syms Maximum
syms Inflection
syms CP
%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(1+(x^2))/(1-(x^2))
fp(x) = 
%Solve for the roots of fp
root1 = solve(fp,x)
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 = "Increasing"
elseif (fp(c+h)<0)
IoDR = "Decreasing"
end
IoDR = "Increasing"
%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
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= "Maximum"
elseif IoDL=="Decreasing" & IoDR =="Increasing"
CP= "Minimum"
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 = diff(fp,x)
cc(x) = 
%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
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 ])
Error using sym>convertChar
Character vectors and strings in the first argument can only specify a variable or number. To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.

Error in sym>tomupad (line 1624)
S = convertChar(x);

Error in sym (line 397)
S.s = tomupad(x);

Error in sym/privResolveArgs (line 1184)
argout{k} = sym(arg);

Error in sym/privBinaryOp (line 1216)
args = privResolveArgs(A, B);

Error in + (line 7)
X = privBinaryOp(A, B, 'symobj::zipWithImplicitExpansion', '_plus');

Respuestas (1)

VBBV
VBBV el 4 de Oct. de 2022
Editada: VBBV el 4 de Oct. de 2022
%syms CP
Comment this line and try as CP is symbolic. Then you get know whether it's maximum or minimum
  3 comentarios
Girbaud
Girbaud el 6 de Oct. de 2022
"try as CP is symbolic"
how would I input this?
VBBV
VBBV el 6 de Oct. de 2022
In the given code, the if-else condition for IoDL and IoDR variables are not satisfied since they are both increasing. so, output of CP will be unknown. In order to input CP, c and h needs to computed in such a way that condition is satisfied so that CP can be determined either as minimum or maximum strings.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by