ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 13 May 2019 17:14:37 +0200Rearranging expressions to minimize negative signshttps://ask.sagemath.org/question/46502/rearranging-expressions-to-minimize-negative-signs/ SageMath newbie still learning the basics here. My goal is to mostly use Sage for basic arithmetic and calculus. I'm playing with some basic equations here, but I can't seem to figure out how to rearrange the output the way I'd like.
For instance:
f, s, s_i = var("f, s, s_i")
thin_lens_formula = 1/f == 1/s + 1/s_i
solve(thin_lens_formula, s)[0]
Output:
s == -f*s_i/(f - s_i)
I'd prefer this to be expressed as `s == f*s_i / (s_i - f)`, multiplying both numerator and denominator by -1 so there is one less negative sign in total. Is there a way to do this or is Sage not really meant to be micro-managed like this?
relatively_randomMon, 13 May 2019 17:14:37 +0200https://ask.sagemath.org/question/46502/simplify_rational gives different resultshttps://ask.sagemath.org/question/29753/simplify_rational-gives-different-results/ I am doing basic vector algebra calculation.
var('x0 y0 z0 a b c d')
B=vector([x0, y0, z0])
n=vector([a,b,c])
A=vector([0,0,d/c])
ab=B-A
proj=ab.dot_product(n)/n.norm()^2*n
However simplifying <code>proj</code> does not give me the expected results
proj.norm().simplify_rational()
Gives me:
sqrt((a^2*x0^2 + b^2*y0^2 + c^2*z0^2 - 2*a*d*x0 + d^2 + 2*(a*b*x0 -
b*d)*y0 + 2*(a*c*x0 + b*c*y0 - c*d)*z0)/(a^2 + b^2 + c^2))
However if I use the following addtional steps
tt=ab.dot_product(n)/n.norm()^2
(tt*n.norm()).simplify_rational()
The result is satisfactory:
(a*x0 + b*y0 + c*z0 - d)/sqrt(a^2 + b^2 + c^2)
In addition, if I ommit parenthesis the results become different again:
tt*n.norm().simplify_rational()
Results in
sqrt(a^2 + b^2 + c^2)*(a*x0 + b*y0 + c*(z0 - d/c))/(a*conjugate(a) +
b*conjugate(b) + c*conjugate(c))
And
(tt*n).norm().simplify_rational()
Results in
sqrt((a^2*x0^2 + b^2*y0^2 + c^2*z0^2 - 2*a*d*x0 + d^2 + 2*(a*b*x0 -
b*d)*y0 + 2*(a*c*x0 + b*c*y0 - c*d)*z0)/(a^2 + b^2 + c^2))
What are the exact difference? How do I ensure getting the desired outcome?neomaxSun, 04 Oct 2015 14:05:58 +0200https://ask.sagemath.org/question/29753/how to get simplified result of solving equationhttps://ask.sagemath.org/question/28853/how-to-get-simplified-result-of-solving-equation/Hi there!
In a linear algebra assignment I have the following equation I need to find a solution for:
`-2*sqrt(3)*sin(t)^2+2*cos(t)*sin(t)+sqrt(3)==0`. I know the result is pi/3.
Now, when I use solve, `solve(-2*sqrt(3)*sin(t)^2+2*cos(t)*sin(t)+sqrt(3)==0, t)`. I get:
[sin(t) == -1/6*sqrt(3)*(sqrt(cos(t)^2+6)-cos(t), sin(t) == 1/6*sqrt(3)*sqrt(cos(t)^2+6)+cos(t))].
How do I use the solve function to get the more simplified result?
NB: I have also tried to use `find_root` and different simplify functions, but also without any luck. I am new to sage, so it is quite possible that I don't know a specification to the solve function which I should use.
Thank you in advance!
Sincerly SimonismonMon, 17 Aug 2015 19:38:14 +0200https://ask.sagemath.org/question/28853/How to get sage to NOT calculatehttps://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/I would like to be able to give some variables a value and have sage show it to me in a pritty format.
For example if i have;
a = 2
b = 3
and then I input a+b and sage returns 2+3
Is there a command that let me do this? ToddiSat, 08 Jun 2013 14:37:56 +0200https://ask.sagemath.org/question/10207/