Thank you for the pointer to Heaviside functions. I tried it, but
unfortunately it gives an AttributeError.
Best regards,
George
~~~~~~~~~~~~~`
from sympy import symbols, Heaviside
x,y,C1,C2,C3 = symbols('x y C1 C2 C3')
W = 1.0
L = 1.0
A1 = 1.0
A2 = 1.0
sigma_max = 1.0
strain_max = 1.0
strain = C1*x+C2*y+C3
filter1 = Heaviside(strain) - Heaviside(strain-strain_max) # Subtract two
heaviside functions
filter2 = Heaviside(strain-strain_max) # Subtract two heaviside functions
sigma = 1e6*(filter1*(A1*strain**2+A2*strain) + filter2*sigma_max)
F_c = sigma.integrate((x,-W/2,W/2),(y,-L/2,L/2))
print 'F_c',F_c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On Tuesday, November 12, 2013 12:55:06 AM UTC+2, Aaron Meurer wrote:
>
> As a workaround, if you can expression your function in terms of
> Heaviside, SymPy *may* be able to compute the integral.
>
> Aaron Meurer
>
> On Mon, Nov 11, 2013 at 11:48 AM, Aaron Meurer
> <[email protected]<javascript:>>
> wrote:
> > I think integrating piecewise where the variable appears in the
> > conditions in a non-trivial way may require implementing some new
> > algorithm. See https://code.google.com/p/sympy/issues/detail?id=2128
> > and https://code.google.com/p/sympy/issues/detail?id=3801.
> >
> > Aaron Meurer
> >
> > On Mon, Nov 11, 2013 at 11:17 AM, George Gerber
> > <[email protected]<javascript:>>
> wrote:
> >> Good day,
> >> My ultimate goal is to solve for the coefficient of a piecewise
> function
> >> that is integrated.
> >> Example:
> >>
> >> from sympy import solve, symbols, Piecewise
> >> x, C1 = symbols('x C1')
> >> strain = C1*x
> >> # Linear strain distribution assumption
> >> stress = Piecewise((strain**2,strain>0),(strain**3,strain>1)) #
> >> Stress-stain relationship of material
> >> Force = stress.integrate((x,-1,1))
> >> # Force = integral of stress over an area
> >> sol = solve([Force-1],[C1])
> >> # Find the strain distribution which will balance the specified force
> >>
> >> Is this possible or is this too advanced for sympy (even in near
> future)?
> >>
> >> Best regards,
> >> George
> >>
> >>
> >> On Monday, 11 November 2013 06:58:04 UTC+2, George Gerber wrote:
> >>>
> >>> Good day,
> >>>
> >>> The integration of a piecewise function below results in a single
> numeric
> >>> number, instead of producing a piecewise equation containing the
> symbols
> >>> 'C1', 'C2' and 'C3'.
> >>> Is this a bug?
> >>>
> >>> Best regards,
> >>> George
> >>>
> >>> ~~~~~~~~~~~~~~~~~~~~~~~~
> >>>
> >>> from sympy import symbols, Piecewise
> >>> x,y,C1,C2,C3 = symbols('x y C1 C2 C3')
> >>>
> >>> W = 1.0
> >>> L = 1.0
> >>> A1 = 1.0
> >>> A2 = 1.0
> >>> sigma_max = 1.0
> >>> strain0 = 1.0
> >>>
> >>> strain = C1*x+C2*y+C3
> >>>
> >>> sigma =
> >>>
> 1e6*Piecewise((0,strain>0),(A1*strain**2+A2*strain,strain>strain0),(sigma_max,True))
>
>
> >>> F_c = sigma.integrate((x,-W/2,W/2),(y,-L/2,L/2))
> >>>
> >>>
> >>> print 'F_c',F_c
> >>> ~~~~~~~~~Result is:~~~~~~~~~~~~~
> >>> F_c 500000.000000000
> >>>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "sympy" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an
> >> email to [email protected] <javascript:>.
> >> To post to this group, send email to [email protected]<javascript:>.
>
> >> Visit this group at http://groups.google.com/group/sympy.
> >> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.