Ask Your Question

jeanpat's profile - activity

2023-03-26 22:39:55 +0200 received badge  Famous Question (source)
2022-02-17 15:08:17 +0200 received badge  Notable Question (source)
2022-02-17 15:08:17 +0200 received badge  Popular Question (source)
2020-12-14 21:00:05 +0200 received badge  Famous Question (source)
2020-10-11 08:57:41 +0200 received badge  Famous Question (source)
2020-10-11 08:57:41 +0200 received badge  Notable Question (source)
2020-10-11 08:57:41 +0200 received badge  Popular Question (source)
2020-10-10 13:03:45 +0200 received badge  Notable Question (source)
2020-10-10 13:03:45 +0200 received badge  Popular Question (source)
2018-08-07 16:27:43 +0200 received badge  Notable Question (source)
2016-06-17 21:05:01 +0200 received badge  Popular Question (source)
2015-02-27 23:01:37 +0200 received badge  Famous Question (source)
2014-01-03 13:11:32 +0200 asked a question hold=True fails to prevent simplification on numeric value

Hi, The following code shows the steps for resolving an equation:

x = var('x')
b = var('b')
b = -6
qe = x+b== 7
L=qe.lhs()
R=qe.rhs()

ex = "<h3> Solve : $ x+ ({0}) =7 $ </h3>".format(b)
ex2 = "<h3> Solve : ${0} $ </h3>".format(str(L)+'='+str(R))
html(ex+ex2)
show(qe)

show(str(L.add(6, hold=True))+'='+str(R.add(6, hold=True)))
show(qe+6)

I was waiting for the second step displayed as:

(x-6)+6=7+6

but the equation is displayed as:

(x-6)+6=13

Is there a way to show the operation performed on both side of the equation?

Thank you

Jean-Patrick

2014-01-03 10:57:28 +0200 received badge  Editor (source)
2014-01-03 10:49:49 +0200 asked a question checking left hand side of an equation

Hi, I'd like to check if the operation applied to an equation yields the solution as follow: a=var('a') eq= a+7==6

print eq.lhs()
LHS =(eq-7).lhs()
print LHS
LHS==a
a is a
LHS is a

I was waiting that the line LHS==a yields True or False. How can I check that LHS contains the variable a?

edit

`LHS is a`

yields False

2014-01-03 09:48:09 +0200 commented answer embeding a variable in some html code in cloud.sagemath

Thanks a lot. By the way would you know a way to avoid having things like x+-1=12 (I could use brackets too ...)

2014-01-03 09:45:25 +0200 received badge  Scholar (source)
2014-01-03 09:45:25 +0200 marked best answer embeding a variable in some html code in cloud.sagemath

You can do this by using the html function directly:

Background

%html just works on text -- it doesn't perform any sage (or python) parsing. It does this by applying sage's html function to whatever you type. So your code above is equivalent to

html("""
<h2> R&eacute;solvons une &eacute;quation </h2>
<font size="+3">
        <div align="center">
            $ x+ b=k $
        </div>
    </font>

<h3> Exemple :  r&eacute;soudre : $ x+$ <sage>nombre</sage>$=12 $ </h3>
""")

[Note that I had to change é to &eacute; in the last line for it to parse correctly -- hopefully this will not be necessary in a future update of sage.]

Solution

So the key to doing what you want is using sage to create the string with the variable value inserted, and then pass the result to the html function. The format operator is a good way to do this:

beginning = """
<h2> R&eacute;solvons une &eacute;quation </h2>
<font size="+3">
        <div align="center">
            $ x+ b=k $
        </div>
    </font>

"""
exemple = "<h3> Exemple :  r&eacute;soudre : $ x+ {0} =12 $ </h3>".format(nombre)

html(beginning+exemple)    # addition for strings is concatenation

Followup

You can see what's happening by just printing the strings:

print(exemple)

should show you something like

<h3> Exemple : r&eacute;soudre : $ x + 7 =12 $ </h3>

because the format operator sticks the value of nombre into the the string.


Edit

To fix things like x + -1, define the right hand side as a sage expression and let sage format it:

var('x')
nombre = nombres[3]
expr = x + nombre

The string for expr should give you x - 1. If your expressions get more complicated, you can also use latex(expr) to get a latex formatted string (for things like exponents, parentheses, etc).

2014-01-03 08:24:24 +0200 asked a question embeding a variable in some html code in cloud.sagemath

Hello, I try to produce an equation and to display it as follow:

import random
nombres = [-3, 1, -4, -1, 5, 2, 7]
nombre = random.choice(nombres)

%html
<h2> R&eacute;solvons une &eacute;quation </h2>
<font size="+3">
        <div align="center">
            $ x+ b=k $
        </div>
    </font>

<h3> Exemple :  résoudre : $ x+$ <sage>nombre</sage>$=12 $ </h3>

But the last line failed to display the value of nombre in the equation

What is the good way to do that? Thank you

2014-01-03 07:40:28 +0200 commented answer embed sage vars in html notebook cell

Doing this in cloud.sagemath fails: x=2;%html; We can see that <sage>x</sage> is the key result

2013-12-12 05:09:33 +0200 asked a question convert a symbolic var into a numeric var

Hello, How to compute y or to draw a point of coord (sol, 0) ?

Thank you

sol=solve(2*x+1==7,x)
print sol
print sol[0], type(sol), type(sol[0])
#y=2*sol+7
#print y

#plot(sol,0)
2013-11-29 11:57:25 +0200 received badge  Taxonomist
2013-11-26 03:12:43 +0200 received badge  Notable Question (source)
2013-10-18 16:56:27 +0200 received badge  Student (source)
2013-09-23 21:18:30 +0200 received badge  Popular Question (source)
2013-05-09 14:26:54 +0200 asked a question How to load a local image from cloud.sagemath?

Hello, I tried naively to load an image in a worksheet from my cloud.sagemath account. Something like:

from scipy import ndimage as nd
image=nd.imread('~/path/to/image.jpg')

and of course that failed. Is there a way to do that?

thank you

jp

2012-09-24 12:39:09 +0200 received badge  Nice Answer (source)
2012-09-24 03:18:22 +0200 received badge  Teacher (source)
2012-09-23 09:22:06 +0200 answered a question Mathematical Morphology?

For python you can use mahotas, pymorph, scikits-image, mamba. There's also things in scipy

2012-09-22 14:47:26 +0200 commented answer factor() issue with second degre polynomes

Thank you again.

2012-09-22 13:53:50 +0200 commented answer factor() issue with second degre polynomes

Thank you. So I have to know "before" that the roots contain a sqrt(2).

2012-09-22 11:20:31 +0200 asked a question factor() issue with second degre polynomes

Hello, In a sagenb worksheet, I'am trying to factor two 2° polynomes R and H as follow:

from sage.misc.latex import pretty_print
x=var('x')
R(x)=9*(x-5)**2-4
f3=R.factor()
H(x)=2*(x+5)**2-4
f4=H.factor()
pretty_print('R(x)=',f3)
pretty_print('H(x)=',f4)

I get :

R(x)=(3x-17)(3x-13) as waited
but H(x)=2x**2+20x+46

I can develop the factorized H as:

test=(sqrt(2)*(x+5)-2)*(sqrt(2)*(x+5)+2)
pretty_print(test.radical_simplify())

which yields:

2x**2+20x+46

Is there a kind of "radical_factor()" ? Thank you

2012-09-18 16:51:13 +0200 received badge  Supporter (source)