[CAS problem] Highprecision operations in numerical solution equations

04012020, 01:03 PM
(This post was last modified: 04012020 01:24 PM by yangyongkang.)
Post: #1




[CAS problem] Highprecision operations in numerical solution equations
Hi everyone, I recently came across an x = tan (x) equation about x. Find x> 0, the solution over the interval [k * pi, (k + 1/2) * pi] (k is a positive integer). It is found that when k is taken large, the error occurs.
Code: subst(tan(x)x,x=fsolve(tan(x)=x,x=100000.5*pi)) Very large error。 mathematica supports highprecision operations Code: FindRoot[Tan[x]  x, {x, 100000.5*Pi}, WorkingPrecision > 30] I wrote it in C (dichotomy), compared it, and found that the error increases with increasing k. Code: #include<stdio.h> Contrast with MMA, found this Code: Show[ListPlot @@@ {{#1^2*Sin[#2  #1] & @@@ Red represents the MMA result, blue represents the C language calculation result, and the accuracy gap is widened. study hard, improve every day 

04012020, 06:14 PM
(This post was last modified: 04012020 06:16 PM by Albert Chan.)
Post: #2




RE: [CAS problem] Highprecision operations in numerical solution equations
(04012020 01:03 PM)yangyongkang Wrote: Hi everyone, I recently came across an x = tan (x) equation about x. Find x> 0, the solution over the Solver might converge to a root outside your required interval. It is better to solve for x, then calculate tan(x)x XCas> guess := 10000.5*pi XCas> fsolve(tan(x)=x, x=guess) → 7.72525183694 XCas> fsolve(tan(x)=x, x=guess) → 4.49340945791 XCas> guess := 100000.5*pi → 314160.836155 XCas> x := fsolve(tan(x)=x,x=guess) → 314160.836155 (not shown, but slightly less than guess) XCas> tan(guess)  guess → 27378944702.1 XCas> tan(x)  x → 4735723246.82 XCas> x := 314160.836152 // Error for x is tiny, only 0.000003 XCas> tan(x)  x → 11691.0416004 For large guess (=pi/2 + k*pi), solved x is only slightly smaller. We can estimate tan(x) = cot(guessx) ≈ 1/(guessx), and x ≈ guess XCas> x := guess  1/guess // "solved" tan(x)=x, we have x = 314160.836152123 

04022020, 12:00 PM
Post: #3




RE: [CAS problem] Highprecision operations in numerical solution equations
Your guess is at a singularity of the tan function (k*pi+pi/2), it's not surprising. You should rewrite your equation with atan
fsolve(x=atan(x)+100000*pi,x=100000*pi+pi/2) 

04032020, 05:29 AM
Post: #4




RE: [CAS problem] Highprecision operations in numerical solution equations
(04022020 12:00 PM)parisse Wrote: Your guess is at a singularity of the tan function (k*pi+pi/2), it's not surprising. You should rewrite your equation with atan About function header replacement, such as defining an anonymous function, f = lambda x, y: x + y,list(a,b)=[a,b] I want f to act on list (a, b) and replace list with f. Replace list (a, b) with f (a, b). A bit more complicated, such as list (list (a, b) ...), I want to replace the innermost list with f. Based on your ideas, I wrote a bit of code. Code: plotlist((lambda l:map(range(0,length(l)1),lambda index:(l[index])^2*sin(l[index+1](l[index]))))([seq(fsolve(equal(x,atan(x)+k*π),equal(x,(k+0.5)*π)),equal(k,1 .. 10000))])) Got the error storm graph。 study hard, improve every day 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)