How to find derivative equal to 0?
29 views (last 30 days)
Show older comments
So I'm trying to find where the derivative of a function is equal to zero, and at what x-value.
x8 = linspace(-2, 2, 100);
y8diff = -(((x8.^2 - 1).*sin(x8 + 0.1) + x8.*cos(x8 + 0.1))./((sqrt(1-x8.^2).*(cos(x8 + 0.1).^2))));
We're not allowed to use MatLabs Toolbox
4 Comments
Star Strider
on 9 Oct 2022
What are you allowed to use?
x8 = linspace(-2, 2, 100);
y8diff = -(((x8.^2 - 1).*sin(x8 + 0.1) + x8.*cos(x8 + 0.1))./((sqrt(1-x8.^2).*(cos(x8 + 0.1).^2))));
figure
yyaxis left
plot(x8, real(y8diff));
ylabel('Real')
yyaxis right
plot(x8, imag(y8diff))
ylabel('Imaginary')
grid
.
Answers (2)
Walter Roberson
on 9 Oct 2022
y8diff = @(x8) -(((x8.^2 - 1).*sin(x8 + 0.1) + x8.*cos(x8 + 0.1))./((sqrt(1-x8.^2).*(cos(x8 + 0.1).^2))));
That is, turn it into an anonymous function. Now create a second anonymous function that is the square of the above, and fzero the second function.
The graph that Star Strider created hints that there might be two zeros, both close to 1.5
3 Comments
Walter Roberson
on 9 Oct 2022
the initial guess. You should probably try with a guess below 1.4 and another above 1.6
Walter Roberson
on 11 Oct 2022
y8diff = @(x8) -(((x8.^2 - 1).*sin(x8 + 0.1) + x8.*cos(x8 + 0.1))./((sqrt(1-x8.^2).*(cos(x8 + 0.1).^2))));
syms x8
y8d = y8diff(x8);
eqn = y8d.^4
vpasolve(eqn, 1.4)
vpasolve(eqn, 1.5)
fplot(eqn, [0.5 1.2])
fplot([real(y8d), imag(y8d)], [0 0.8])
fplot([real(y8d), imag(y8d)], [2 2.7])
X0 = linspace(0,40, 100);
roots_found = arrayfun(@(X) double(vpasolve(eqn, X)), X0)
plot(X0, roots_found)
u = uniquetol(roots_found)
diff(u)
There seem to be an indefinite number of roots with the difference between them looking like it tends to pi
Image Analyst
on 9 Oct 2022
So you want where the real part of y8diff and the imaginary part of y8diff are both zero at the same time. Like the two places around 1.4 and 1.5 in Star's plot above? I think you'll have to do it symbolically since if you do it numerically, there is no index where both the real and imaginary parts are zero.
%Star's code but with a lot finer sampling.
x8 = linspace(-2, 2, 10000);
y8diff = -(((x8.^2 - 1).*sin(x8 + 0.1) + x8.*cos(x8 + 0.1))./((sqrt(1-x8.^2).*(cos(x8 + 0.1).^2))));
figure
yyaxis left
plot(x8, real(y8diff));
ylabel('Real')
yyaxis right
plot(x8, imag(y8diff))
ylabel('Imaginary')
grid
% Now see where real and imaginary parts are both zero at the same time:
yr = real(y8diff);
yi = imag(y8diff);
index0 = find((yr == 0) & (yi == 0))
2 Comments
Image Analyst
on 10 Oct 2022
That tells you that there are 50 elements in your vector that have a value of exactly 0. I don't know what you plan on doing with that information -- you didn't tell us. You said you just have to find out where it is zero.
See Also
Categories
Find more on Calculus 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!