Can someone help me how to code the missing parts? because I don't have enough knowledge to code the needed equations.
1 view (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1142715/image.png)
Answers (1)
Walter Roberson
on 3 Oct 2022
On lines 21 and 23 you need to assign IoDR either "Increasing" or "Decreasing". You will need to use your knowledge of mathematics to figure out which is appropriate to assign on which of the lines.
Likewise on lines 28 and 30 you will need to assign IoDL either "Increasing" or "Decreasing". You will need to use your knowledge of mathematics to figure out which is appropriate to assign on which of the lines.
On lines 35 and 37 you will need to assign CP either "Maximum" or "Minimum". You will need to use your knowledge of mathematics to figure out which is appropriate to assign on which of the lines.
On line 44 you will need to figure out how to solve the equation fpp(x) == 0 for x to find the list of x values that are the inflection points. Doing so will solve the programming task and so you will solve the homework.
2 Comments
Sabina Victoria
on 4 Oct 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))
%Set the distance to the left/right of the critical point
h=0.01
%Find the first derivative of the function
fp(x) = diff(1+(x^2))/(1-(x^2))
%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);
%Find the points of inflection of the function by equating the second derivative of the function to zero.
cc = 0
%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 = 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 need help with the second derivative... it keeps saying
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');
Error in solution (line 70)
text(c+.5,f(c),["("+string(c)+","+string(f(c))+") "+CP ])
Walter Roberson
on 4 Oct 2022
You build up a string object using string() and the + operation. Then at the end you + CP where for whatever reason you decided that it would be a good idea to make CP symbolic instead of a string constant.
You assumed in your code that if you + a string object and a symbolic object, that the symbolic object would be converted to string and then the two strings would be concatenated. But it turns out that when you do that operation, matlab instead tries to convert the string to symbolic and do a symbolic addition...
I would suggest that you should make CP and CP2 into string objects, like "Minimum"
See Also
Categories
Find more on Symbolic Variables, Expressions, Functions, and Preferences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!