Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Need to split function into terms and then plot
Replies: 2   Last Post: Oct 30, 2013 12:10 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bob Hanlon

Posts: 891
Registered: 10/29/11
Re: Need to split function into terms and then plot
Posted: Oct 30, 2013 12:10 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


u[x_] := c0 + c1*x + c2*x^2


coef = {c0, c1, c2};


r = {u1, u2, u3};


Clear[le];


col = Collect[u[x] /.
Solve[r == (u /@ {0, le, le/2}),
coef], r][[1]]


u3*((4*x)/le - (4*x^2)/le^2) +
u1*(1 - (3*x)/le + (2*x^2)/le^2) +
u2*(-(x/le) + (2*x^2)/le^2)


{n1, n2, n3} = Coefficient[col, #] & /@ r


{1 - (3*x)/le + (2*x^2)/le^2,
-(x/le) + (2*x^2)/le^2,
(4*x)/le - (4*x^2)/le^2}


Module[{le = le = 1.5},
Plot[{n1, n2, n3}, {x, 0, le},
PlotLegends -> {"n1", "n2", "n3"}]]



Bob Hanlon




On Mon, Oct 28, 2013 at 11:22 PM, Honza Vorel <honzavorel@gmail.com> wrote:

> I am a newbie and need help please. I hope I can express myself clearly
> enough, so you can understand me.
>
> #I have a function:
> u[x_]:=c0+c1 * x +c2 * x^2
>
> #And I am interested in these three points 0,le/2 and le (length)
> points={0,le/2,le}
>
> #When I map the above together
> c=Map[u,points]
>
> #I'll get c0, c0+c1*le/2+c2*le^2/4, c0+c1*le + c2 * le^2
>
> #define my deflection vector
> r={u1,u2,u3}
>
> #Solve for c0,c1,c2
> c=Solve[c==r,{c0,c1,c2}]
> #I'll get c0->u1, c1->(3u1-4u2+u3)/le and c2-> 2(u1-2u2+u3)/le^2
>
>
> #replace c into u[x_]
> u[x]/.c
>
> # separate by variable u1,u2,u3
> Collect[%,{u1,u2,u3}]
>
> #I'll get {u1(1+2x^2/le^2-3x/le)+u3(2x^2/le^2-x/le)+u2(-4x^2/le^2+4x/le)}
>
> #Now I need to separate the above like this (le=1.5):
>
> # n1=(1+2x^2/le^2-3x/le)
> # n2=(-4x^2/le^2+4x/le)
> # n3=(2x^2/le^2-x/le)
>
> # And I don't know how.
>
> # So I can plot it: Plot[{n1,n2,n3},{x,0,1}]
> # Thanks for your help.
>
> Honza
>
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.