Ask Your Question

Thorsten's profile - activity

2023-08-26 23:21:36 +0100 received badge  Taxonomist
2018-11-10 09:34:31 +0100 received badge  Notable Question (source)
2017-02-14 14:39:47 +0100 received badge  Popular Question (source)
2017-01-25 18:14:33 +0100 received badge  Good Answer (source)
2015-04-24 19:37:52 +0100 asked a question Implicit plot in tachyon scene

Is there a way to get some implicit plot, or some other graphic object in general into a tachyon scene? Something like:

t = Tachyon(xres=400,yres=400, camera_center=(4,30,30), look_at=(0,0,0))
t.ImplicitPlot3d( ... )

Or can I modify the camera_center parameter when using the tachyon viewer in the show() method?

2015-03-31 11:16:12 +0100 received badge  Nice Answer (source)
2015-02-23 09:39:44 +0100 received badge  Self-Learner (source)
2015-02-23 08:43:09 +0100 answered a question Solve behaviour on same equation twice

I have now looked at the underlying code for solve. It turns out that if the first argument of solve is an equation or a list of just one equation the object function sage.symbolic.expression.Expression.solve is used. This explains why the output of

solve([sin(x)==0,sin(x)==0],x

and

solve([sin(x)==0],x)

may differ. To force to get all solutions in the first case one can use

solve(sin(x)==0,x,to_poly_solve='force')

Another thing I've found out is that in the definition of the underlying maxima function solve is declared as solve ([eqn_1, …, eqn_n], [x_1, …, x_n]) so the number of equations should match the number of variables.

If one reformulates the problem to

 solve(-sin(x)*sin(x)==0,x,to_poly_solve='force')

all solutions will be displayed.

However I liked the behaviour of previous Versions of sage That is: If solve could't find a solution the original equation was returned. That way it was clear that there may exist solutions sage could not found.

2015-02-22 12:16:01 +0100 answered a question What does assume(x, "real")?

It is a good thing, that bool(x^2>0) evaluates to false. Just plug in the real value 0.

However in version 6.4 of sage

 sage:  assume(x,'real')
 sage:  bool(x*x>=0)

evaluates to true.

2015-02-22 06:59:17 +0100 received badge  Enlightened (source)
2015-02-22 06:59:17 +0100 received badge  Good Answer (source)
2015-02-21 22:51:01 +0100 received badge  Nice Answer (source)
2015-02-21 20:19:34 +0100 received badge  Editor (source)
2015-02-21 18:17:16 +0100 answered a question Something like RealDigits in Sage?

To get the binary representation just add a .str(base=2) to the approximated value.

 sage:  a = pi + sqrt(2)
 sage:  a.n(digits=10).str(base=2)
 '100.1000111001001001010100001111000010'

For the other direction the method RR is useful. Given as first argument the string and as second the base.

 sage:  s= a.n(digits=60).str(base=2)
 sage:  RR(s,2)
 4.55580621596289
2015-02-17 07:45:29 +0100 answered a question How can I print equations just like latex?

There is the hold option, which might can help:

 z(x)=x.power(2).mul(x,hold=true)
 view(z)

which evaluates to $x \mapsto x^2x$ For an easier typing one could use Infix opertors:

 def hold_mult(a,b):
     return a.mul(b,hold=true)
 h = infix_operator('multiply')(hold_mult)

and then use x^2 *h* x.

However in your case if you need just the initial equation to display it might be the easiest just to print it as a string. If you need this functionality more often, an (extendet version of a) function like this could be helpful:

def paranthese_match(prefix,str):
   matches = []
   while (str.find(prefix) != -1):
       p = -1
       for li in [str.find(prefix)+len(prefix)..len(str)-1]:
           if str[li] == '(':
             p -=1
           if str[li] == ')':
             p += 1
           if p==0:
              matches.append(str[str.find(prefix)+len(prefix):li])
       str = str[li:]
   return matches
def print_expression(str):
   str = str.replace('*',' \cdot ')
   str = str.replace('pi',' \pi ')
   for sr in paranthese_match('sqrt(',str):
       str = str.replace('sqrt('+sr+")",'\sqrt{'+sr+'}')
   for sr in paranthese_match('exp(',str):
       str = str.replace('exp('+sr+")",'e^{'+sr+'}')
   html("$"+str+"$")

Then print_expresion("6/(5*pi*h*50*h*(x^2+25))*h*exp((-x+sqrt(x^2+25))/50)") leads to $6/(5 \cdot \pi \cdot h \cdot 50 \cdot h \cdot (x^2+25)) \cdot h \cdot e^{(-x+\sqrt{x^2+25})/50}$

2015-02-16 18:51:47 +0100 received badge  Good Question (source)
2015-02-16 14:39:23 +0100 received badge  Nice Question (source)
2015-02-16 11:09:47 +0100 commented question built in method norm of Vector_symbolic_dense object

Are your shure this is the code in your worksheet? It seems like you left out the parenthesis in .norm()

2015-02-16 10:09:51 +0100 received badge  Scholar (source)
2015-02-16 10:03:27 +0100 asked a question Solve behaviour on same equation twice

Two questions: The first one: Solving an equation:

solve(sin(x)==0,x)

gives the solution [a=pi] but

solve([sin(x)==0,sin(x)==0],x)

raises to the somehow better solution [[a == pi*z425]] Where is the difference between the two equations?

A second one: A previous version of sage 5.something could solve

solve([sin(x)==0,-sin(x)==0],x)

However Sage 6.4.1 Returns an empty list.

2013-06-28 14:45:45 +0100 commented answer different color on backside of surface

This is in fact much easier and faster. Seeing this solution I'm a bit ashamed, that it's so simple. But thank you very much for pointing this out.

2013-06-28 10:40:18 +0100 received badge  Self-Learner (source)
2013-06-28 10:40:18 +0100 received badge  Teacher (source)
2013-06-28 10:40:15 +0100 received badge  Student (source)
2013-06-28 05:13:55 +0100 answered a question different color on backside of surface

If someone deals with a similar problem it might help seeing my (messy) code for this:

def plottosided(f,color):
     P = implicit_plot3d(f(x,y,z),(x,-1.5,1.5),(y,-1.5,1.5),(z,-1.5,1.5),plot_points=20,frame=False,viewer='tachyon')
     opts = P._process_viewing_options({})
     T = P._prepare_for_tachyon(opts['frame'],opts['axes'], opts['frame_aspect_ratio'],opts['aspect_ratio'],opts['zoom'])
     R=newtriangle(f,T.tachyon(),0.001)

     R=R.replace('resolution 400 400','resolution 500 500')
     print('Converting complete')
     tachyon_rt(R)

def tovector(A):
    B=[]
    for a in A:
        if a!='':
            B += [float(a)]
    return vector(B)

def tostring(v): 
    s=''
    for i in v:
        s+= str(i)+' '
    return s
def newtriangle(f,S,C): #f defining implicit function, S the tachyon string, C the second rgb color

    Colorstring = str(color[0])+' '+str(color[1])+' '+str(color[2])

    Triangles = S.split('TRI')
    Pre = Triangles[0]
    App = Triangles[len(Triangles)-1]
    Triangles=Triangles[1:len(Triangles)-1]

    newtexture=' Texdef texture89\n  Ambient 0.230769230769 Diffuse 0.769230769231 Specular 0.0 Opacity 1\n   Color '+Colorstring+'\n   TexFunc 0\n\n'

    Ret=Pre + newtexture
    count = 1
    max = len(Triangles)
    step= floor(max/10)+1
    for Triangle in Triangles:
        if (count%step==0):
            print (count/step).str() + '0%'
        Triangle2 = normalshifted(f,Triangle,-0.001)
        Ret += 'TRI'+Triangle + 'TRI' + Triangle2
        count += 1
    Ret += 'TRI' +App
    return Ret

def normalshifted(f,T,shift): #f defining function, T  TriangleString
    V0=tovector(T[T.find('V0')+2:T.find('V1')].split(' '))
    V1=tovector(T[T.find('V1')+2:T.find('V2')].split(' '))
    V2=tovector(T[T.find('V2')+2:T.find('\n')].split(' ')) 
    Suf=T[T.find('\n'):]
    #normal = ((V2-V0).cross_product(V1-V0)).normalize()
    SP=1/3*(V0+V1+V2)
    normal=vector(f.gradient()(SP[0],SP[1],SP[2])).n()
    V0=shift*normal+V0
    V1=shift*normal+V1
    V2=shift*normal+V2
    String = ' V0 ' +tostring(V0)+'V1 '+tostring(V1)+'V2 '+tostring(V2)+'\ntexture89\n'
    return String

And a Test with a simple sphere:

f(x,y,z)=x^2+y^2+z^2-3
color=(0.9, 0.2, 1.0) 
plottosided(f,color)
2013-06-28 04:54:01 +0100 received badge  Supporter (source)
2013-06-27 19:40:15 +0100 commented answer different color on backside of surface

Thank you very much for your ideas. As my surface is a algebraic variety (Kummer surface) the second idea is a bit difficult. So I tried the third one. I hoped that the normal is determined by the order of the vertices in the triangle, but this seems rather random. In my case I could calculate the normals via the gradient. Unfortunately the rendering is now very slow. I hope I can increase the speed a bit by cleaning up my code.

2013-06-26 17:38:03 +0100 asked a question different color on backside of surface

Hey,

I want to animate a 3D plot. Therefore I generate tachyon rendered implicit plots which I then send to ffmpeg. This works quite well. The only disadvantege, is that it's during the video hard to distinguish which side of the surface one sees. Therefore I want to change the color of the backside or at least increase the shadow.

I already tried some stuff with the tachyon raytracer building a scene. But this does not work for implicit plots. The solution given here seems not to be very usefull in this context.

Is there perhaps a simply trick, which does the job?