mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2020-07-29, 08:08   #1
rockzur
 
Aug 2019

2×3 Posts
Default How to solve this equation with pari gp ...

I don't know how to put the solve command on the pari gp command line to solve logarithmic equations. Can somebody help me.
rockzur is offline   Reply With Quote
Old 2020-07-29, 12:06   #2
a1call
 
a1call's Avatar
 
"Rashid Naimi"
Oct 2015
Remote to Here/There

76816 Posts
Default

As I was taught by Paul Underwood,
To get log (x) in base n use
log(x)/log(n)
Pari-GP gives the natural log of the number otherwise known as ln(x) by the rest of the world.

Last fiddled with by a1call on 2020-07-29 at 12:14
a1call is offline   Reply With Quote
Old 2020-07-30, 07:31   #3
rockzur
 
Aug 2019

68 Posts
Default

I mean how to solve for example 2 ^ x -5 = -6. Using the solve command
rockzur is offline   Reply With Quote
Old 2020-07-30, 07:52   #4
axn
 
axn's Avatar
 
Jun 2003

13·192 Posts
Default

Code:
? ?solve
solve(X=a,b,expr): real root of expression expr (X between a and b), where expr(a)*expr(b)<=0.
Your sample equation boils down to 2^x+1=0, which doesn't have real roots. Let's try with an equation that does.

2^x-5==0. We need to know an interval (a,b) where a root lies. We know that 2^2 < 5 < 2^3. So let's try (2,3)
Code:
? solve(x=2, 3, 2^x-5)
%2 = 2.3219280948873623478703194294893901759
axn is offline   Reply With Quote
Old 2020-07-30, 08:23   #5
rockzur
 
Aug 2019

2·3 Posts
Default

It would be solve(2^x=8); For example
rockzur is offline   Reply With Quote
Old 2020-07-30, 09:54   #6
axn
 
axn's Avatar
 
Jun 2003

13·192 Posts
Default

Quote:
Originally Posted by rockzur View Post
It would be solve(2^x=8); For example
No. You give a real valued expression in one variable, and it will find one real-valued solution where the expression becomes zero. So you recast your equation as 2^x-8=0 and just give the left side of the equality as input.

Code:
? solve(t=0,10,2^t-8)
%1 = 3.0000000000000000000000000000000000000
axn is offline   Reply With Quote
Old 2020-07-30, 12:04   #7
R. Gerbicz
 
R. Gerbicz's Avatar
 
"Robert Gerbicz"
Oct 2005
Hungary

101011100012 Posts
Default

Quote:
Originally Posted by axn View Post
Code:
? ?solve
solve(X=a,b,expr): real root of expression expr (X between a and b), where expr(a)*expr(b)<=0.
What is missing here is that you need a continuous function. Otherwise the result is crap:
Code:
? solve(x=0,3,if(x<2,-1,1))
%3 = 1.9999999999999999999999999999999999999
?
R. Gerbicz is offline   Reply With Quote
Old 2020-07-30, 12:14   #8
rockzur
 
Aug 2019

2·3 Posts
Default

What I want to know is how is used solve command.
rockzur is offline   Reply With Quote
Old 2020-07-30, 13:56   #9
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

32×13×29 Posts
Default

Code:
?solve
solve(X=a,b,expr): real root of expression expr (X between a and b), where 
expr(a)*expr(b)<=0.
For logarithmic equations use pen and paper and an internet search engine.

Last fiddled with by paulunderwood on 2020-07-30 at 14:26
paulunderwood is offline   Reply With Quote
Old 2020-07-30, 14:45   #10
R. Gerbicz
 
R. Gerbicz's Avatar
 
"Robert Gerbicz"
Oct 2005
Hungary

7·199 Posts
Default

Quote:
Originally Posted by rockzur View Post
What I want to know is how is used solve command.
Good question, it is not binary search, it should be another root finding algorithm. Btw in some really trivial cases the solve breaks:
Code:
? solve(x=-1,2,x^3)
  ***   at top-level: solve(x=-1,2,x^3)
  ***                              ^----
  ***   sorry, solve recovery [too many iterations] is not yet implemented.
  ***   Break loop: type 'break' to go back to GP prompt
break>
What is interesting is that their approx roots was so close to the x=0 solution, don't know why they haven't aborted the search.
Code:
? solve(x=-1,2,print(x);x^3)
-1.0000000000000000000000000000000000000
2.0000000000000000000000000000000000000
-0.66666666666666666666666666666666666667
-0.53132832080200501253132832080200501253
-0.39585716304753417148752640416134559761
0.80207141847623291425623679791932720119
-0.26729770261219306942169777701737070320
...
-4.1842288737629149621829297627585343823 E-26
8.5184705351226720431227968573430956740 E-26
-2.8383161799160252299934361727339277773 E-26
  ***   at top-level: solve(x=-1,2,print(x);x^3)
  ***                              ^-------------
  ***   sorry, solve recovery [too many iterations] is not yet implemented.
  ***   Break loop: type 'break' to go back to GP prompt
R. Gerbicz is offline   Reply With Quote
Old 2020-07-31, 19:54   #11
jane477
 
Jul 2020

1 Posts
Default

Quote:
Good question, it is not binary search, it should be another root finding algorithm. Btw in some really trivial cases the solve breaks:
Code:
? solve(x=-1,2,x^3)
  ***   at top-level: solve(x=-1,2,x^3)
  ***                              ^----
  ***   sorry, solve recovery [too many iterations] is not yet implemented.
  ***   Break loop: type 'break' to go back to GP prompt
break>
What is interesting is that their approx roots was so close to the x=0 solution, don't know why they haven't aborted the search.
Code:
? solve(x=-1,2,print(x);x^3)
-1.0000000000000000000000000000000000000
2.0000000000000000000000000000000000000
-0.66666666666666666666666666666666666667
-0.53132832080200501253132832080200501253
-0.39585716304753417148752640416134559761
0.80207141847623291425623679791932720119
-0.26729770261219306942169777701737070320
...
-4.1842288737629149621829297627585343823 E-26
8.5184705351226720431227968573430956740 E-26
-2.8383161799160252299934361727339277773 E-26
  ***   at top-level: solve(x=-1,2,print(x);x^3)
  ***                              ^-------------
  ***   sorry, solve recovery [too many iterations] is not yet implemented.
  ***   Break loop: type 'break' to go back to GP prompt
what an elegant solution
jane477 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to solve: k(b^m)-z=n*d. ? JM Montolio A Miscellaneous Math 18 2018-03-09 15:32
The FBI wants YOU to help solve a murder ixfd64 Puzzles 4 2011-03-30 12:25
Solve for mod function flouran Miscellaneous Math 23 2009-01-04 20:03
An Equation to Solve davar55 Puzzles 3 2008-10-09 00:35
Solve this equation davar55 Puzzles 52 2007-06-26 21:41

All times are UTC. The time now is 12:45.

Sat Sep 19 12:45:22 UTC 2020 up 9 days, 9:56, 1 user, load averages: 1.90, 1.66, 1.50

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.