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.Sun, 15 May 2016 06:03:29 +0200Different syntax to solvehttps://ask.sagemath.org/question/33361/different-syntax-to-solve/ I've below equation( j.mp/sage_emi ) involving 4 variables. I've fixed 3 variables' values, but can't get the 4th variables' value (both, including numerical). Can someone fix the code? Manually, I can get the answer for emi as 1210/21.
P, emi, rate, duration = var("P emi rate duration")
eq1 = P = emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
solve([eq1, P == 100, duration == 2, rate == 10], emi)
It would be helpful if someone writes 2,3 different sage code to achieve the same above objective.
I'm just curious can we do this:
solve([eq1], rate)
Wed, 11 May 2016 07:32:54 +0200https://ask.sagemath.org/question/33361/different-syntax-to-solve/Answer by ndomes for <p>I've below equation( j.mp/sage_emi ) involving 4 variables. I've fixed 3 variables' values, but can't get the 4th variables' value (both, including numerical). Can someone fix the code? Manually, I can get the answer for emi as 1210/21.</p>
<pre><code>P, emi, rate, duration = var("P emi rate duration")
eq1 = P = emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
solve([eq1, P == 100, duration == 2, rate == 10], emi)
</code></pre>
<p>It would be helpful if someone writes 2,3 different sage code to achieve the same above objective.</p>
<p>I'm just curious can we do this:</p>
<pre><code>solve([eq1], rate)
</code></pre>
https://ask.sagemath.org/question/33361/different-syntax-to-solve/?answer=33370#post-id-33370 P, emi, rate, duration = var("P emi rate duration")
eq1 = P == emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
eq2 = eq1.subs(P=100,duration=2,rate=10)
solve(eq2, emi)
Please note the double equal sign ( == ) between P and emi* ...Wed, 11 May 2016 16:08:41 +0200https://ask.sagemath.org/question/33361/different-syntax-to-solve/?answer=33370#post-id-33370Comment by Sukrit-Gupta for <pre><code>P, emi, rate, duration = var("P emi rate duration")
eq1 = P == emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
eq2 = eq1.subs(P=100,duration=2,rate=10)
solve(eq2, emi)
</code></pre>
<p>Please note the double equal sign ( == ) between P and emi* ...</p>
https://ask.sagemath.org/question/33361/different-syntax-to-solve/?comment=33404#post-id-33404Thanks for the neat code.
Can you please explain why the below code doesn't work:
P, emi, rate, duration = var("P emi rate duration")
eq1 = P == emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
eq3 = P == 100
eq4 = duration == 2
eq5 = rate == 10
sol = solve([eq1, eq3, eq4, eq5], emi)
It looks like 4 equations, and only one variable to solve.Fri, 13 May 2016 20:02:36 +0200https://ask.sagemath.org/question/33361/different-syntax-to-solve/?comment=33404#post-id-33404Answer by Sukrit-Gupta for <p>I've below equation( j.mp/sage_emi ) involving 4 variables. I've fixed 3 variables' values, but can't get the 4th variables' value (both, including numerical). Can someone fix the code? Manually, I can get the answer for emi as 1210/21.</p>
<pre><code>P, emi, rate, duration = var("P emi rate duration")
eq1 = P = emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
solve([eq1, P == 100, duration == 2, rate == 10], emi)
</code></pre>
<p>It would be helpful if someone writes 2,3 different sage code to achieve the same above objective.</p>
<p>I'm just curious can we do this:</p>
<pre><code>solve([eq1], rate)
</code></pre>
https://ask.sagemath.org/question/33361/different-syntax-to-solve/?answer=33409#post-id-33409Apart from the good answer given by @ndomes , here are some codes:
In eq1, correct the sign between P and emi (and I think the number of "variables to solve for" should be atleast equal to number of equations to get a solution):
P, emi, rate, duration = var("P emi rate duration")
eq1 = P == emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
solve([eq1, P == 100, duration == 2, rate == 10], [emi, P, duration, rate])
The below code is same but visually different:
P, emi, rate, duration = var("P emi rate duration")
eq1 = P == emi * (( 1 + rate / 100)^ duration - 1) / (rate / 100) / (1 + rate /100)^ duration
eq3 = P == 100
eq4 = duration == 2
eq5 = rate == 10
solve([eq1, eq3, eq4, eq5], [emi, P, duration, rate])
Sun, 15 May 2016 06:03:29 +0200https://ask.sagemath.org/question/33361/different-syntax-to-solve/?answer=33409#post-id-33409