Ask Your Question

No able to get the results from the last segment

asked 2015-06-08 22:35:28 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I am giving my full code below. I am unable to get the results from code marked in red. Rest is working fine

html('<center><h2>Tyre Design</h2></b>by : Madan Saini')
#Input Parameters
PI = pi.n()
def myplot(t_size=input_box('3.00-18',label='Tyre Size',width=20),od=input_box(round(627,2),label='Tyre Outer Dia.',width=20), sw=input_box(round(80,2),label='Tyre Section Width',width=20), nsd=input_box(round(6.5,2),label='Non Skid Depth',width=20), ut=input_box(round(2.5,2),label='Under Tread',width=20), bn=input_box(round(0,0),label='No of Breakers',width=20), bg=input_box(round(1.2,2),label='Breaker Gauge',width=20), pn=input_box(round(2,0),label='No of Plies',width=20), pg=input_box(round(0.85,2),label='Ply Gauge',width=20), rg=input_box(round(2.5,2),label='Side Rubber Gauge',width=20), rim_d=input_box(round(458.7,2),label='Rim Dia (D)',width=20), rim_w=input_box(round(65,0),label='Rim Width(A)', width=20),rim_f=input_box(round(14,2),label='Rim Flange Height(G)',width=20), beta_c=input_box(40,label='Crown Angle',width=20), auto_update=False):

#Initial guess: Assume the closest ellipse
    rc = ((od/2)-nsd-ut-(bn*bg)-(pn*pg/2))
    W = ((sw/2)-rg-(pn*pg/2))
    rb = ((rim_d/2)+rim_f-(pn*pg*1.5))
    zb = rim_w/2.0
    rw_init = rc*(rb/rc+sqrt(1-(zb/W)^2))/(1+sqrt(1-(zb/W)^2))
    rw = var('rw')
    Bc = var('Bc')
    def find_tire_width(data):
        rw = data[0]
        Bc = data[1]
        r = var('r')
        F = (r^2-rw^2)*sqrt(rc^2-r^2*sin(Bc)^2)/sqrt((rc^2-rw^2)^2*rc^2*cos(Bc)^2-(r^2-rw^2)^2*(rc^2-r^2*sin(Bc)^2))
        z = function('z',r)
        d2 = desolve_rk4(diff(z,r)+F,z,ics=[rc*0.9999,0],end_points=(rw-(rc-rw)/2),step=-(rc-rw)/2000)
        S = spline(d2)
        return [S(rw), S(rb)]

    Bc = (90-beta_c)/180*PI
    zwb = find_tire_width([rw_init, Bc])
    show("calculated rc = " + str(rc))
    show("calculated W = " + str(W))
    show("calculated rb = " + str(rb))
    show("calculated zb = " + str(zb))
    show("calculated Bc = " + str(Bc))    
    show("rw_init based on elliptical approximation = "+str(rw_init))
    show("zw in the natural shape = " + str(zwb[0]))
    show("zb in the natural shape = " + str(zwb[1]))

from this point the code is not showing any results

def f(input):
    zwb = find_tire_width(input)
    return ((W-zwb[0])^2+(zb-zwb[1])^2);

c1 = lambda input: input[0]-rb
c2 = lambda input: rc - input[0]
c3 = lambda input: input[1]
c4 = lambda input: pi/2 - input[1]
a = minimize_constrained(f,[c1, c2, c3, c4],[rw_init, Bc])
show("rw in the optimal shape = " + str(a[0]))
show("Beta in the optimal shape = " + str(a[1]) + " radians")

please help me out to solve this issue..

edit retag flag offensive close merge delete


Still looking for the answer from someone. Please help me out..

madan26 gravatar imagemadan26 ( 2015-06-11 04:40:20 -0500 )edit

You haven't made it very clear exactly what error message you are receiving, and your code is fairly long, so I think people are scared off a bit. It's important to provide a minimal example that isn't working, when possible.

kcrisman gravatar imagekcrisman ( 2015-06-11 20:32:17 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2015-06-12 23:55:30 -0500

madan26 gravatar image

dear kcrisman, thanks for your comments. I am not getting any error. Just not able to get the show results. If I dont use the interact than it is working fine. This problem is that I am using the def command with in def and not able to get the values from the first def. if I use last def as different, means without indents than I got no error but it also dont show the results.

edit flag offensive delete link more


When I paste in your code, the first box works fine as far as I can see. The second box fails because rw_init is not defined.

Pasting in the code for rw_init doesn't work because it refers to a multitude of variables that aren't defined either (the ones that are parameters to myplot).

So I don't believe that you're giving us exactly the code you're executing and that yet you don't get any errors.

nbruin gravatar imagenbruin ( 2015-06-22 17:22:57 -0500 )edit

answered 2015-06-11 20:42:13 -0500

kcrisman gravatar image

In an older Sage (5.6) I get the following very nasty traceback.

capi_return is NULL
Call-back cb_calcfc_in__cobyla__user__routines failed.
Traceback (most recent call last):
TypeError: Error executing code in Maxima
Maxima ERROR:
Expecting a number when the initial state is replaced in the equations, but instead found: 


rk(odes=-sqrt(36881329/400-92425547*r^2/101387157)*(36506*r^2-2499558239)/(36506*sqrt(92425547*r^2*(36506*r^...,state=dummy_dvar,initial=0,domain=[r,303.619635,240.675997139,-0.0209913342871])(dynamics.mac line 392)
 -- an error. To debug this try: debugmode(true);

Now, what this all says to me is the following: Maxima is trying to solve a differential equation in order to get in the constrained minimize function. But apparently f is rather more complicated than your previous uses of find_tire_width. In particular, it looks like somehow in your initial value for one of the things it is trying while minimizing gives a complex number as an initial value! -44.46235161288734/(-1)^0.5

But to try to debug this properly would require someone who really understood your specific situation, as this is a pretty complicated numerical setup. My uninformed guess is that one of your inputs is really close to some badly behaved point in your DE, but I am not at all a numerical analyst so I won't hazard anything more specific than that.

As I point out in the comment, if you can turn this into something simpler that has the same problem, that would help. There is a lot of extraneous stuff, especially the interact; why not just plug in very specific numbers and see if you can get the same problem?

edit flag offensive delete link more


I ran it in the SageCellServer and Sage has a lot to say: "RuntimeWarning: tp_compare didn't return -1 or -2 for exception" with a page of code ending in "TypeError: double_from_pyobj failed in converting argument f of call-back function cb_calcfc_in__cobyla__user__routines to C double". Above my head but and too much going on but perhaps running in Sage Cell Server will help rather than old Sage5.6. I'm not sure why there's no error for madan26.

dazedANDconfused gravatar imagedazedANDconfused ( 2015-06-14 14:38:57 -0500 )edit

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


Asked: 2015-06-08 22:35:28 -0500

Seen: 232 times

Last updated: Jun 12 '15