I am again stuck with similar question which I asked earlier. I am trying to solve x*tan(x)-0.5=0,but when i cross checked the result I am getting very different results.
syms x
n=10;
for n = 1:2:n
x1 = (n-1/2)*pi;
x2 = (n)*pi;
w(n) = double(vpasolve(x*tan(x)-0.5 == 0,x,[x1 x2]))
check(n)=w(n)*tan(w(n))-0.5
end
I am getting
w =
1.5708 0 7.8540 0 14.1372 0 20.4204 0 26.7035
check =
1.0e+16 *
2.5653 0 2.5653 0 2.5653 0 -2.0830 0 -3.6311. I am unable to find my mistake.

 Risposta accettata

Torsten
Torsten il 27 Mar 2022
Modificato: Torsten il 27 Mar 2022
x1=0:0.1:1.3;
y1=x1.*tan(x1)-0.5;
x2=2:0.1:4.1;
y2=x2.*tan(x2)-0.5;
x3=5.5:0.1:6.9;
y3=x3.*tan(x3)-0.5;
plot(x1,y1,x2,y2,x3,y3)
So was your choice of x1 and x2 resonable ?
Here you get the asymptotic distribution of the zeros of your function in order to make a proper choice of x1 and x2:

6 Commenti

I'm unfamiliar with this problem. Was the issue caused by numerical sensitivity? I compared plot with fplot. fplot shows the true graph because the asymptotes are not part of .
x = -3*pi:0.001:3*pi;
y = x.*tan(x) - 0.5;
plot(x, y)
axis([min(x) max(x) -40 40])
fplot(@(x) x*tan(x) - 0.5, [-3*pi 3*pi])
Torsten
Torsten il 27 Mar 2022
I just meant to say that there should be no singularity in between the x1 and x2 values given to "vpasolve".
rakesh kumar
rakesh kumar il 27 Mar 2022
thanks for your replies and correcting my mistakes. the valus of x1 is (n-1)*pi and x2 is (n-1/2)*pi. However, I am gettting similar kind of answer. could you suggest an interval for odd n to solve xtanx-0.5
thanks to all of you
Torsten
Torsten il 27 Mar 2022
Modificato: Torsten il 27 Mar 2022
But I gave you the link which suggests choosing something like
x1 = sqrt(0.5) - 1/6*0.5^1.5 - 0.1 x2 = sqrt(0.5) - 1/6*0.5^1.5 + 0.1
for the first root and
x1 = n*pi + 0.5/(n*pi) - 0.1 and x2 = n*pi + 0.5/(n*pi) + 0.1
for the other roots.
Didn't you look into it ?
syms x
n = 10;
x1 = sqrt(0.5) - 1/6*0.5^1.5 - 0.1;
x2 = sqrt(0.5) - 1/6*0.5^1.5 + 0.1;
w(1) = double(vpasolve(x*tan(x)==0.5,x,[x1,x2]))
for i=1:n
x1 = i*pi + 0.5/(i*pi) - 0.1;
x2 = i*pi + 0.5/(i*pi) + 0.1;
w(i+1) = double(vpasolve(x*tan(x)==0.5,x,[x1,x2]))
end
% Check
w.*tan(w)-0.5
rakesh kumar
rakesh kumar il 28 Mar 2022
Thanks once again. I ran your code and its giving the perfect answer. You people are really great!
Sam Chak
Sam Chak il 28 Mar 2022
Modificato: Sam Chak il 28 Mar 2022
Learned something today. Thank you.
Also thanks for showing an interesting question.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by