How to find derivative equal to 0?

29 views (last 30 days)
Amanda
Amanda on 9 Oct 2022
Commented: Walter Roberson on 11 Oct 2022
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
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
.
Amanda
Amanda on 9 Oct 2022
I guess everything except for syms x

Sign in to comment.

Answers (2)

Walter Roberson
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
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
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
eqn = 
vpasolve(eqn, 1.4)
ans = 
0.52134986062092355768691638558689
vpasolve(eqn, 1.5)
ans = 
2.6217707005409009447216985496563
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)
roots_found = 1×100
0.5213 0.5213 0.5213 2.6218 2.6218 2.6218 2.6218 2.6218 2.6218 2.6218 2.6218 2.6218 6.0138 6.0138 6.0138 6.0138 6.0138 6.0138 6.0138 6.0138 9.2154 9.2154 9.2154 9.2154 9.2154 9.2154 9.2154 12.3853 12.3853 12.3853
plot(X0, roots_found)
u = uniquetol(roots_found)
u = 1×14
0.5213 2.6218 6.0138 9.2154 12.3853 15.5434 18.6960 21.8453 24.9927 28.1388 31.2839 34.4285 37.5725 40.7161
diff(u)
ans = 1×13
2.1004 3.3920 3.2016 3.1699 3.1582 3.1525 3.1493 3.1474 3.1461 3.1452 3.1445 3.1440 3.1437
There seem to be an indefinite number of roots with the difference between them looking like it tends to pi

Sign in to comment.


Image Analyst
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))
index0 = 1×0 empty double row vector
  2 Comments
Amanda
Amanda on 10 Oct 2022
Edited: Amanda on 10 Oct 2022
I'm only looking for real solutions. When I try to use find(real(y8diff) == 0), I get an error message saying:
"Check for incorrect argument data type or missing argument in call to function 'real'."
Edit: Nevermind, solved the error message. However, I get an 1x50 double vector. What should I do with it?
Image Analyst
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!