MATLAB Answers

Solving differential equation with parameters takes forever

조회 수: 8(최근 30일)
I have 2 main equations
psi = 1
theta(0) = -pi/4
phi = 0.2
x(0) = -pi/2
I defined x z theta(t) and x(t) symbolically, and tried to solve with dsolve using symbolic toolbox. When I solve the first equation, I get two answers parametrized by z1 and z18, respectively. When I try to plug in one of the values into the second equation, it takes forever to solve, and never return an answer so I end up pausing it. Is there a faster and simpler way to solve this?

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 8 Jul 2020
If both x and theta varies with t you cannot solve one first and the other separately later, you should treat them as a system of coupled ODEs. Since both equations are nonlinear and they don't have simple analytical solutions you might get further faster with numerical integration of the system. Have a look at ode45 and the numerical ode-examples.

  댓글 수: 3

Cengizhan Demirbas
Cengizhan Demirbas 8 Jul 2020
Thanks a lot, I did as you said and it seems to work without a problem. There is also another equation that i am solving together with these two:
and z(0) = -pi/2
I am trying to plot a graph of x and z, with both ranging from -pi to pi. But I dont have much experience with MATLAB and don't exactly know how to do it. I tried to do this, but it didn't give the plot i wanted:
Can you help me?
%theta = y(1) x = y(2) z = y(3)
init = [-pi/4 -pi/2 -pi/2];
tspan = [0, 10];
[t, yout] = ode45(f, tspan, init);
Bjorn Gustavsson
Bjorn Gustavsson 8 Jul 2020
Well, you can proceed in so many different ways with the output, this is what I typically start off with:
First I plot the individual components as a function of time:
for i1 = 1:3
% or all in one panel...
That should give you a first view of what the solution looks like. Then I'd try what you did, possibly it is also worthwhile to use the comet and comet3 functions to see how the solution moves in your 2 and three components. For this it is preferable to get the solution at equally spaced steps in time. If I model a physical system with some constants of motion (momentum, energy etc) I'd also have a look at how those properties behave. But as you see, from here we could look at this in so many different ways that you will have to try those that seem to lead you to what you want out - it is just to try everything you can think of that is interesting and see what sticks.

댓글을 달려면 로그인하십시오.

추가 답변(0개)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by