Ask Your Question
0

about solve() 2 equations

asked 2017-06-25 16:34:55 +0100

ortollj gravatar image

updated 2017-06-30 17:52:06 +0100

Hi I have 2 questions

1) Why, when I tell SageMath that k is a real number SageMath continues to give me complex solutions for k ?

2) why solve([k^3==4*C,equC],k,C) does not work ?

(when I uncomment the last line in the code below) I suppose the code is not correct ?.

edited[june 27] because can't put new code in comment (I've been told is too long)

forget()
t = var('t') # define a variable t
p = var('p') # constant cubic coeff 
q = var('q') # last constant cubic coeff
Delta = var('Delta') # cubic Discriminant  
theta = var('theta') # variable angle theta 
k = var('k') # real factor
C = var('C') #real  multiplicatif factor
f = function('f')(t) # define f to be a function of t
Delta=-27*q^2 -4*p^3
assume(Delta>0) # 3 real roots
assume(p, 'real')
assume(q, 'real')
equ=t^3 + p*t + q==0
trigequ=4*(cos(theta))^3 -3*cos(theta)==cos(3*theta)
equ1=equ.substitute(t=k*cos(theta))
equf=equ1.lhs()-q==C*trigequ.lhs()
show(equf)
#solve([equf],C,k)
equC=-3*C==k*p
equD=k^3==4*C
show([equD,equC])
Result=solve([equD,equC],k,C)
for j in range(len(Result)) :
    show(Result[j])
edit retag flag offensive close merge delete

Comments

Short answer: The program which does the solving (Maxima) explicitly does not take such assumptions into account when doing so, while it does for other algorithms like integration.

kcrisman gravatar imagekcrisman ( 2017-06-26 14:17:11 +0100 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2017-06-26 15:03:03 +0100

ndomes gravatar image

Answer to the second question:

solve returns a list of solutions. So you get something like solve([equ1,[equ2]],k,C).

You have to refer to an equation in the list:

solve([k^3==4*C,equC[0]],k,C)
edit flag offensive delete link more

Comments

Thanks ndomes, yes it' an list or an array I should have find it on my own. sorry !

but why

Result=solve([k^3==4*C,equC[0]],k,C)
show(Result[0])

does gives me [k=0,C=0] Surely it is not the good way to code ?

or maybe the assume() I put are not enough ?

I think I need to tell SageMath that k and C are the unknowns

ortollj gravatar imageortollj ( 2017-06-26 18:26:49 +0100 )edit

In the end, to be clearer, how can I code so that when I have 2 equations like these:

   -3*C==k*p and k^3==4*C

SageMath gives me the answer for k=f(p) and C=f(p) ?

 -3*C==k*p
k==-3*C/p
k^3==4*C
k^3==(-3*C/p)^3 =4*C
k^3==C^2 * C * (-3/p)^3 ==4*C
C^2 * (-3/p)^3 ==4
C^2 ==4*(p/-3)^3
C   ==2*(p/-3)^(3/2)
####
k==-3*(2*(p/-3)^(3/2))/p

C == (-2 * p) * sqrt(-p) / (sqrt(3) * 3)

k == 2 * sqrt(-p) / sqrt(3)

i made an attempt adding an assume(p<0) without success

WolframAlpha has no problem with these 2 equations

solve(-3*C==k*p  ,k^3==4*C,p<0) for C and k

C = -(2 sqrt(-p^3 ...
(more)
ortollj gravatar imageortollj ( 2017-06-28 18:27:16 +0100 )edit
0

answered 2017-07-13 17:10:05 +0100

ortollj gravatar image

Finally I find a way to solve these two equations. ;-) surely not optimal, But at least it does!

forget()
t = var('t') # define a variable t
p = var('p') # constant cubic coeff 
q = var('q') # last constant cubic coeff
Delta = var('Delta') # cubic Discriminant  
theta = var('theta') # variable angle theta 
k = var('k') # real factor
C = var('C') #real  multiplicatif factor
f = function('f')(t) # define f to be a function of t
Delta=-27*q^2 -4*p^3
assume(Delta>0) # 3 real roots
assume(p, 'real')
assume(q, 'real')
assume(C, 'real')
assume(k, 'real')
equC=-3*C==k*p
equD=k^3==4*C
ResultC=solve(equD,C)
for j in range(len(ResultC)) :
    show(ResultC[j])
Rk=solve(equC.substitute(ResultC[j].lhs()==ResultC[j].rhs()),k)
del(Rk[len(Rk)-1])
show(Rk)
RC0=solve(equD.substitute(Rk[0].lhs()==Rk[0].rhs()),C)
#show(RC0)
RC=[RC0[0],solve(equD.substitute(Rk[1].lhs()==Rk[1].rhs()),C)[0]]
show(RC)
edit flag offensive delete link more
0

answered 2017-07-16 22:54:50 +0100

Emmanuel Charpentier gravatar image

Concerning (1), see casus irreductibilis in Wikipedia.

Life is hard...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-06-25 16:34:55 +0100

Seen: 653 times

Last updated: Jul 16 '17