Clear Filters
Clear Filters

how i convert (0.345346329292023) to 1-sqrt(3/7)

13 views (last 30 days)
how i convert (0.345346329292023) to 1-sqrt(3/7)
  3 Comments
sadeem alqarni
sadeem alqarni on 21 Mar 2018
Yes I want the method to take some arbitrary value
Walter Roberson
Walter Roberson on 21 Mar 2018
The Maple programming language has a function named identify that tries to deal with these situations. If you happen to have Maple then in Maple command
kernelopts(opaquemodules=false);
showstat(identify:-isAlg);
to see the code.

Sign in to comment.

Answers (2)

James Tursa
James Tursa on 21 Mar 2018
Edited: James Tursa on 21 Mar 2018
I don't think you are going to be able to do this in general. The Symbolic Toolbox can help with some simple forms involving square roots, but recovering a radical form for an arbitrary number is probably too much to ask. Particularly since you aren't starting with an exact value of the radical form to begin with. E.g.,
>> sym(sqrt(3/7))
ans =
(3^(1/2)*7^(1/2))/7
>> sym(1-sqrt(3/7))
ans =
1555301599913323/4503599627370496
>> sym(nthroot(2,3))
ans =
5674179970822795/4503599627370496
It was able to recover the simple sqrt of an integer ratio, but once you throw in some additional arithmetic it "punts" and simply returns the equivalent rational fraction for the floating point value. It doesn't even recover the simple cube root of 2 either.
So, simple square root expressions it can recover, but anything beyond that probably not. There may be ways to manipulate things to get more help if you know something about the resulting radical form you expect, but you will probably never get a generic capability for arbitrary values like you seem to be asking for.
  1 Comment
John D'Errico
John D'Errico on 21 Mar 2018
Edited: John D'Errico on 21 Mar 2018
As James says, you can never intelligently recover some totally general form in terms of radicals. If you KNEW it was a pure sqrt, well, yes. But even something as simple as a sum of terms will be nearly impossible. Worse, put a cube root in there, and you are in deeper trouble yet.
Good luck, for example, in recovering the radical form that generated this number:
X =
0.27398020095128
Even if I told you that there are 4 terms in the expression that created it, it would take some serious computing time to recover the original expression I used. Worse, I could add that there are infinitely many variations on that expression that MIGHT have been involved, if you would allow me to get tricky.

Sign in to comment.


sadeem alqarni
sadeem alqarni on 22 Mar 2018
Edited: Stephen23 on 22 Mar 2018
syms y(x) aj xn h yn yn2 fn fn2 fn1 a0 a1 a2 a3 a4 a(j) t k x q1 r fnr yn1 s fn2 fns rr
m=[1,xn,xn^2,xn^3,xn^4,xn^5,xn^6;
1,xn+h,(xn+h)^2,(xn+h)^3,(xn+h)^4,(xn+h)^5,(xn+h)^6;
0,0,2,6*xn,12*xn^2,20*xn^3,30*xn^4;
0,0,2,6*(xn+r*h),12*(xn+r*h)^2,20*(xn+r*h)^3,30*(xn+r*h)^4;
0,0,2,6*(xn+h),12*(xn+h)^2,20*(xn+h)^3,30*(xn+h)^4;
0,0,2,6*(xn+s*h),12*(xn+s*h)^2,20*(xn+s*h)^3,30*(xn+s*h)^4 ;
0,0,2,6*(xn+2*h),12*(xn+2*h)^2,20*(xn+2*h)^3,30*(xn+2*h)^4]
b=[yn;yn1;fn;fnr;fn1;fns;fn2]
z=[a(0);a(1);a(2);a(3);a(4);a(5);a(6)]
z==m\b
w=[1,x,x^2,x^3,x^4,x^5,x^6]
y=(w*(m\b))
y2=subs(y,x,(xn+t*h))
r1=simplify(collect(y2,[fn,fnr,fn1,fns,fn2]))
[c,q] = coeffs(r1, [ yn,yn1,fns,fnr,fn1,fn,fn2])
c1=simplify(c)
y22=subs(r1,t,2)
[c2,q]=coeffs(y22,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c3=simplify(c2)
f=diff(y2,t)
y33=subs(f,t,2)
[c4,d]=coeffs(y33,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c5=simplify(c4)
y44=subs(r1,t,1)
[c6,q]=coeffs(y44,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c7=simplify(c6)
f=diff(y2,t)
y55=subs(f,t,1)
[c8,d]=coeffs(y55,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c9=simplify(c8)
y66=subs(r1,t,s)
[c10,q]=coeffs(y66,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c11=simplify(c10)
f=diff(y2,t)
y77=subs(f,t,s)
[c12,d]=coeffs(y77,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c13=simplify(c12)
y88=subs(r1,t,r)
[c14,q]=coeffs(y88,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c15=simplify(c14)
f=diff(y2,t)
y99=subs(f,t,r)
[c16,d]=coeffs(y99,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c17=simplify(c16)
y100=subs(r1,t,0)
[c18,q]=coeffs(y100,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c19=simplify(c18)
f=diff(y2,t)
y101=subs(f,t,0)
[c20,d]=coeffs(y101,[ yn,yn1,fns,fnr,fn1,fn,fn2])
c21=simplify(c20)
zz=simplify(subs(y22,{r,s},{sym('1-sqrt(3/7)'),sym('1+sqrt(3/7)')}))
zz1=simplify(subs(y22,{r,s},{0.345346329292023,1.654653670707977})
how i make the output of zz1 equal to zz for any values????
  2 Comments
Walter Roberson
Walter Roberson on 22 Mar 2018
Are your values always of the form A+/-sqrt(B/C) ? Will both numeric values always be available?
If we have
v1 = 0.345346329292023; v2 = 1.654653670707977;
then
V = sort([v1, v2]);
A = round(mean(V));
[B,C] = rat((V(2)-A).^2);
rBC = sqrt(sym(B)/sym(C));
zz1 = simplify(subs(y22, {r,s}, {sym(A)-rBC, sym(A)+rBC});

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!