Student Support Forum: 'Issues with triggered events' topicStudent Support Forum > General > "Issues with triggered events"

 Next Comment > Help | Reply To Topic
 Author Comment/Response Andy 08/21/05 1:38pm Hi, I'm having issues with adding a triggered event to my program. Here's a copy of it below, it should paste fine into mathematica. Appologise for the paste - my university computer wouldn't let me attach it! I've only been using mathematica for a week so plase forgive any crappy looking code, the basis of the program does work however... \!\(\* RowBox[{\({L, M\_p, ρ, A, M\_m, r\_m, r\_p, r\_c, μ, L\_1, L\_2, θ\_1, α, I\_r, M\_r, d\_r, r\_to, r\_ti, τ, a, b} = \ {50000, 1000, 970, 62.83*10^\(-6\), 2000, 0.5, 0.5, 6870000, 3.9877848*10^14, 0.75, 0.75, \((1.4*α)\), 1.831, 0, 0.75, 0.75, 0.006, \ 0.004, 5*10^7, 1.28, 0}\), "\ \[IndentingNewLine]", \(ω = \((\@\(μ/\((r\_c^2)\)\)/r\_c)\)\), "\ \[IndentingNewLine]", \(r\_T = \((\((\((r\_to)\)^2)\) + \(( r\_ti)\)^2)\)\), "\[IndentingNewLine]", \(x\_p1[t] = \((\((r\_c)\)*\(( Cos[θ[t]])\))\) + \((L* Cos[ψ[t] + θ[t]])\) + \((L\_1*Cos[ψ[t] - θ\_1])\) + \((L\_2*Cos[ψ[ t] + β[t] - θ\_1])\)\), "\[IndentingNewLine]", \(y\_p1[ t] = \((\((r\_c)\)*\((Sin[θ[t]])\))\) + \((L*Sin[ψ[t] + θ[t]])\) + \(( L\_1*Sin[ψ[t] - θ\_1])\) + \((L\_2*Sin[ψ[t] + β[t] - θ\_1])\)\), "\[IndentingNewLine]", \(x\_p2[t] = \((\((r\_c)\)*\((Cos[θ[ t]])\))\) - \((L*Cos[ψ[t] + θ[ t]])\) - \((L\_1*Cos[ψ[t] - θ\_1])\) - \((L\_2*Cos[ψ[ t] + β[t] - θ\_1])\)\), "\[IndentingNewLine]", \(y\_p2[t] = \((\((r\_c)\)*\((Sin[ θ[t]])\))\) - \((L*Sin[ψ[ t] + θ[t]])\) - \(( L\_1*Sin[ψ[t] - θ\_1])\) - \((L\_2*Sin[ψ[t] + β[t] - θ\_1])\)\), "\[IndentingNewLine]", \(x\_R1[t] = \((\(( r\_c)\)*\((Cos[θ[t]])\))\) + \((L*Cos[ψ[t] + θ[t]])\) + \ \((d\_r*Cos[ψ[t] + α - θ\_1])\)\), "\[IndentingNewLine]", \(y\_R1[t] = \((\(( r\_c)\)*\((Sin[θ[t]])\))\) + \((L*Sin[ ψ[t] + θ[t]])\) + \((d\_r*Sin[ψ[t] + α - θ\_1])\)\), "\[IndentingNewLine]", \(x\_R2[t] = \((\(( r\_c)\)*\((Cos[θ[t]])\))\) - \((L*Cos[ψ[t] + θ[t]])\) - \ \((d\_r*Cos[ψ[t] + α - θ\_1])\)\), "\[IndentingNewLine]", \(y\_R2[t] = \((\(( r\_c)\)*\((Sin[θ[t]])\))\) - \((L*Sin[ ψ[t] + θ[t]])\) - \((d\_r*Sin[ψ[t] + α - θ\_1])\)\), "\[IndentingNewLine]", \(x\_m[t] = \((\((r\_c)\)*\((Cos[θ[t]])\))\)\), "\[IndentingNewLine]", \(y\_m[t] = \((\((r\_c)\)*\((Sin[θ[t]])\))\)\), "\[IndentingNewLine]", \(x\_T1[t] = \((\((r\_c)\)*\((Cos[θ[ t]])\))\) + \((\((L/2)\)*Cos[ψ[t] + θ[t]])\)\), "\[IndentingNewLine]", \(y\_T1[t] = \((\((r\_c)\)*\((Sin[θ[t]])\))\) + \ \((\((L/2)\)* Sin[ψ[t] + θ[t]])\)\), "\[IndentingNewLine]", \(x\_T2[t] = \((\((r\_c)\)*\((Cos[θ[ t]])\))\) - \((\(( L/2)\)*Cos[ψ[t] + θ[t]])\)\), "\[IndentingNewLine]", \(y\_T2[ t] = \((\((r\_c)\)*\((Sin[θ[t]])\))\) - \((\((L/2)\)*Sin[ ψ[t] + θ[t]])\)\), "\[IndentingNewLine]", RowBox[{ StyleBox[\(I\_p\), "Text"], "=", \((0.5*M\_p*\(( r\_p^2)\))\)}], "\[IndentingNewLine]", \(I\_t = \ \((\((1/12)\)*ρ*A*L*\((\((3*\((r\_T^2)\))\) + \((L^2)\))\))\)\), "\[IndentingNewLine]", \(I\_m = \((0.5*M\_m*\((r\_m^2)\))\)\), "\[IndentingNewLine]", \(\(x'\)\_p1[t] = D[ x\_p1[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_p1[t] = D[ y\_p1[t], t]\), "\[IndentingNewLine]", \(\(x'\)\_p2[t] = D[x\_p2[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_p2[ t] = D[y\_p2[t], t]\), "\[IndentingNewLine]", \(\(x'\)\_R1[t] = D[ x\_R1[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_R1[ t] = D[y\_R1[ t], t]\), "\[IndentingNewLine]", \(\(x'\)\_R2[t] = D[x\_R2[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_R2[t] = D[y\_R2[t], t]\), "\[IndentingNewLine]", \(\(x'\)\_m[ t] = D[x\_m[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_m[ t] = D[y\_m[t], t]\), "\[IndentingNewLine]", \(\(x'\)\_T1[ t] = D[x\_T1[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_T1[t] = D[ y\_T1[t], t]\), "\[IndentingNewLine]", \(\(x'\)\_T2[ t] = D[x\_T2[t], t]\), "\[IndentingNewLine]", \(\(y'\)\_T2[t] = D[ y\_T2[t], t]\), "\[IndentingNewLine]", RowBox[{\(T\_K\), "=", RowBox[{\((0.5*M\_p*\((\((\((\(x'\)\_p1[ t])\)^2)\) + \((\(y'\)\_p1[t])\)^2)\))\), "+", \(( 0.5*M\_p*\((\((\((\(x'\)\_p2[t])\)^2)\) + \((\(y'\)\_p2[t])\)^2)\))\), "+ ", \((0.5*M\_m*\((\((\((\(x'\)\_m[t])\)^2)\) + \((\(y'\)\_m[t])\)^2)\))\), "+", \((0.5*ρ*A*L*\((\((\((\(x'\)\_T1[ t])\)^2)\) + \((\((\(y'\)\_T1[t])\)^2)\))\))\), "+", \ \((0.5*ρ*A*L*\((\((\((\(x'\)\_T2[t])\)^2)\) + \((\((\(y'\)\_T2[ t])\)^2)\))\))\), "+", \((0.5* M\_r*\((\((\((\(x'\)\_R1[t])\)^2)\) + \((\(y'\)\_R1[ t])\)^2)\))\), "+", \((0.5* M\_r*\((\((\((\(x'\)\_R2[t])\)^2)\) + \ \((\(y'\)\_R2[t])\)^2)\))\), "+", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{ StyleBox[\(I\_p\), "Text"], "+", \(I\_t\), "+", \(I\_r\), "+", \((I\_m/2)\)}], ")"}], "*", \((\((\(ψ'\)[t] + \(θ'\)[ t] + \(β'\)[t])\)^2)\)}], ") "}]}]}], "\[IndentingNewLine]", \(U\_p = \(-\((\((μ* M\_p)\)/\((\@\(\((\((r\_c)\)^2)\) + \((L^2)\) + \((2* r\_c*L*Cos[ψ[ t]])\)\))\))\)\) - \((\((μ*M\_p)\)/\((\@\(\((\((r\_c)\)^2)\) + \ \((L^2)\) - \((2* r\_c*L*Cos[ψ[t]])\)\))\))\) - \[IndentingNewLine]\((\((μ*M\_r)\)/\ \((√\((\((\((r\_c)\)^2)\) + \((L^2)\) + \((d\_r^2)\) + \ \((2*r\_c*L*d\_r*Cos[ψ[t]])\))\))\))\) - \((\((μ*M\_r)\)/\((√\((\((\(( r\_c)\)^2)\) + \((L^2)\) + \((d\_r^2)\) - \(( 2*r\_c*L*d\_r*Cos[ψ[t]])\))\))\))\) - \((\((μ* M\_m)\)/\((r\_c)\))\) + \((μ*ρ*A \((\((r\_c)\)*\((Cos[ψ[t]])\))\) - L + \ \@\(\((\((r\_c)\)^2)\) + \((L^2)\) - \((2*r\_c*L*Cos[ψ[t]])\)\))\)/\(( μ*ρ*A \((\(( r\_c)\)*\(( Cos[ψ[t]])\))\) + L + \@\(\((\((r\_c)\)^2)\) + \(( L^2)\) + \((2*r\_c*L* Cos[ψ[t]])\)\))\)\), "\[IndentingNewLine]", \(R\_1 = D[T\_K, \(ψ'\)[t]]\), "\[IndentingNewLine]", \(R\_2 = D[R\_1, t]\), "\[IndentingNewLine]", \(R\_3 = D[ T\_k, ψ[t]]\), "\[IndentingNewLine]", \(R\_4 = D[ U\_p, ψ[t]]\), "\[IndentingNewLine]", \(R\_5 = D[T\_K, \(β'\)[t]]\), "\ \[IndentingNewLine]", \(R\_6 = D[R\_5, t]\), "\[IndentingNewLine]", \(R\_7 = D[T\_k, β[t]]\), \ "\[IndentingNewLine]", \(R\_8 = D[U\_p, β[ t]]\), "\[IndentingNewLine]", \(R\_9 = D[T\_K, \(θ'\)[t]]\), "\ \[IndentingNewLine]", \(R\_10 = D[R\_9, t]\), "\[IndentingNewLine]", \(R\_11 = D[T\_k, θ[t]]\), "\[IndentingNewLine]", \(R\_12 = D[U\_p, θ[ t]]\), "\[IndentingNewLine]", \(eqn = R\_2 - R\_3 + R\_4 - τ\), "\[IndentingNewLine]", \(eq1 = Simplify[eqn]\), "\[IndentingNewLine]", \(eqn2 = R\_6 - R\_7 + R\_8\), "\ \[IndentingNewLine]", \(eq2 = Simplify[eqn2]\), "\[IndentingNewLine]", \(eqn3 = R\_10 - R\_11 + R\_12\ \), "\[IndentingNewLine]", \(eq3 = Simplify[eqn3]\), "\[IndentingNewLine]", \(system = NDSolve[{\ eq1 == 0, \ eq2 == 0, \ eq3 == 0, ψ[0] == 0.9, \(ψ'\)[0] == 0.000001, β[0] == 1.28, \(β'\)[0] == 0, θ[ 0] == 0, \(θ'\)[0] == ω}, \ {ψ, β, θ}, {t, 0, 12000}, MaxSteps -> ∞, AccuracyGoal -> Automatic, PrecisionGoal -> Automatic, WorkingPrecision \ -> 40]\), "\[IndentingNewLine]", \(Plot[Evaluate[\(ψ'\)[ t] /. \ system], {t, 0, 12000}, Frame -> True, FrameTicks -> Automatic, GridLines -> Automatic, FrameLabel -> {time, \(ψ'\)[t]}]\), "\[IndentingNewLine]", \ \(Plot[Evaluate[\(β'\)[t] /. \ system], { t, 0, 12000}, Frame -> True, FrameTicks -> Automatic, GridLines -> \ Automatic, FrameLabel -> {time, \(β'\)[t]}]\), "\[IndentingNewLine]", \(Plot[Evaluate[\(θ'\)[ t] /. \ system], {t, 0, 12000}, Frame -> True, FrameTicks -> Automatic, GridLines -> Automatic, FrameLabel -> {time, \(θ'\)[t]}]\), "\[IndentingNewLine]", \ "Null"}]\) Basically, the system simulates three degrees of freedom. However, I need to introduce an event once Pisdot goes above a certain value(0.062). I'm having real trouble getting it to play ball, I've been using the If statement and even the cases option (I am clueless) as you will be able to see. I'm looking to evaluate the response of beta once the threshold is crossed (beta remains fixed, unable to move until this point). Any help would be greatly appreciated, please excuse my newbieness! Thanks, Andy URL: ,

 Subject (listing for 'Issues with triggered events') Author Date Posted Issues with triggered events Andy 08/21/05 1:38pm Re: Issues with triggered events yehuda ben-s... 08/27/05 10:02pm
 Next Comment > Help | Reply To Topic