Output of solve in maxima and sage have x on both side - solver

I am trying to solve equation
sqrt(x)==sqrt(20*(1500-x))
in sage and getting the output as given bellow,
sqrt(x) == sqrt(-20*x + 30000)
Problem in the above solution is that there is x in both side. How can I solve this kind of question sot that I get proper solution. I have tried the same problem in maxima also and getting same answer.

There are a few options in Sage with solve, and this one seems to help (I assume the answer is okay).
sage: solve(sqrt(x)==sqrt(20*(1500-x)),x,to_poly_solve=True)
[x == (10000/7)]

Related

Prolog find GCD of a list of numbers

Hello I am trying to find the GCD of a list of numbers in Prolog, but I cannot manage to do it.
Could you please help?
I am not even barely close so I wont share any of my work till now.
PP: In the process of trying to solve this I've encountered another problem that I can't solve, if you can help with this one too I will be grateful. It's finding all the common divisors of two numbers.
Thanks!
Thanks to Lurker!
I wasn't using the proper algorithm. I thought of finding GCD of two numbers and then GCD of the result and the next one, but I am not sure why I got confused that this won't work.
Anyway, here is the code:
gcd(0,X,X):- X > 0, !.
gcd(X,Y,Z):- X>=Y, X1 is X -Y, gcd(X1,Y,Z).
gcd(X,Y,Z):- X<Y, X1 is Y-X, gcd(X1,X,Z).
gcdL([H,H1|T],Z):-gcd(H,H1,X),gcdL([X|T],Z).
gcdL([H1,H2],Z):-gcd(H1,H2,Z).
And for the curious here is the retarded approach I was trying to achieve. And I was almost there as the first answer the script gives is correct, but it continues to backtrack. Anyway it's ugly, long, hard and inefficient:
minel([X],X).
minel([H,H1|T],X):-H>H1,minel([H1|T],X).
minel([H,H1|T],X):-H=<H1,minel([H|T],X).
gcdL(L,X):-gcdL(L,X,1).
gcdL(L,X,C):-minel(L,M),C<M,delAll(L,C),Temp is C,C1 is C + 1,gcdL(L,R,C1),X is max(Temp,R).
gcdL(L,X,C):-minel(L,M),C1 is C + 1,C1=<M,gcdL(L,X,C1).
gcdL(L,X,C):-minel(L,M),C=:=M,X is 1.
delAll([T],X):- 0 is mod(T,X).
delAll([H|T],X):- 0 is mod(H,X),delAll(T,X)
Note taken: First find the most proper algorithm, then try to script the problem.
I believe this link will help you
https://math.stackexchange.com/questions/8611/number-of-common-divisors-between-two-given-numbers
insist of count you can store the numbers to a table for example.

How to find inverse function in Wolfram Mathematica?

The question seems too easy to answer, however it is not, since I have to deal with functions that do not have closed forms (or I don't know how to find them). For example, I would like to find inverse functions for:
y == x Tan[x]
and
y == a x + b Tan[x].
Thus far, I used Newton-Rhapson's method for the inverse transformations. It works fine, but requires iterations. I just wonder whether there is a method to prove that there is a better solution or not. I've tried Wolfram Mathematica to find a solution, but since I'm a beginner. I have had no luck to get anything meaningful.
Seems it can't be done.
Solve[y == x Tan[x], x]
Solve::nsmet: This system cannot be solved with the methods available to Solve.
InverseFunction[# Tan[#] &]

Failure of Simplify in Mathematica

My question is about an apparent failure of Mathematica's function "FullSimplify" to simplify an easy algebraic expression.
This is the expression that I ask Mathematica to evaluate:
FullSimplify[Re[a^(I*b)] - Re[a^(-I*b)], Element[a, Reals] && a > 0 && Element[b, Reals]]
This should give the result 0. Instead Mathematica only restates my expression:
Re[a^(-I b) (-1 + a^(2 I b))]
Replacing a and b by actual numbers solves the problem.
What could be the cause of it? How to effectively use FullSimplify (and Simplify, Expand, Integrate and so...)?
I read that the order of variables could play a role here, but I couldn't wrap my head around it.
I tried to check for similar problems on the website as well, but I couldn't find any answer that could explain this phenomenon.
Thanks in advance for your support.

diophantine analysis in maxima

I have defined an extended Euclidean algorithm in Maxima as
ext_euclid(a,b):=block(
[x,y,d,x_old,y_old,d_old],
if b = 0 then return([1,0,a])
else ([x_old,y_old,d_old]:ext_euclid(b,mod(a,b)),
[x,y,d]:[y_old,x_old-quotient(a,b)*y_old,d_old],
return([x,y,d])));
in order to solve linear Diophantine equations of the form a+b=c where gcd(a,b)=1, however if a-b=c I get -1 returned by the algorithm for the divisor but gcd(a,-b) as before. Is my algorithm wrong, or can it be used for a-b=c?
Iain
I don't quite understand what the problem is. Can you please give two examples, one in which the result matches what you expected, and one in which it doesn't (and please say what's your expected result in that case).
EDIT: OP replies: "to solve 5x+7y is 23 ext_euclid (5,7) returns [3,-2,1] where gcd(5,7) is 1 however for 5x-7y is 23 ext_euclid(5,-7) returns [-3,1,-1] but gcd(5,-7) is still 1 this fails Bezout's identity ax+by is gcd(a,b)"
Also if you are trying to implement a particular statement of the algorithm, can you please link to it or copy it here.
OP replies: "code at http://mvngu.wordpress.com/2009/08/25/elementary-number-theory-using-maxima/"
One possible thing to look at: does the mod function behave as you expect it?
OP replies: "mod(5,7) is, mod(5,-7) is -2"

Mathematica problems with certain differential equations and DSolve

Im having trouble getting started. I am in a Financial Engineering program, and I am trying to use a book written in 2003 to help me model partial differential equations, the black scholes model, etc.
But in the introductory chapter there is a very basic ODE interest rate problem, and my output is very different from the book.
DSolve[{y'[t] == ry[t], y[0] == P}, y[t], t]
is what I put in. The book has a very neat solution of {{y(t)->P*exp^(rt)}}
What I get is something like (Note, I can't post the output)
{{y(t) -> integral_1_to_t ry(K[1]]dK[1] - integral_1_to_0 ry(K[1])dK[1]+P}}
What are the big K's? Is this just some rule output that can't generate a symbolic solution? Because of some problem with my set up or filesystem? Also, are there any suggestions for using old books on Mathematica where the code provided may be out of date? I just need to find a way to move forward and apply this to my studies.
Last, sometimes with other ODE's I will get results different than my source. I.E. I followed a Mathematica ODE tutorial and my output was different too. In some places my version of Mathematica won't calculate, or drops certain variable s or constants in the solution, or there is no output. I have browsed for general troubleshooting for DSolve, but have found no persistent and recognized bug. I am wondering if there is something wrong in my file system, or something else? Please help!
You've an space missing between the r and the y[t].
Try:
DSolve[{y'[t] == r y[t], y[0] == P}, y[t], t]

Resources