MATLAB Answers

0

Solving first order differential equation

Saruultugs Batzorig さんによって質問されました 2019 年 10 月 21 日
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 10 月 24 日
Hello, I've tried multiple times to solve the following differential equation in Matlab but no luck so far. I have about 131 different values of U for 131 seconds of time t. A, B, r are constants, y and dy/dt has initial conditions of 0. I want to calculate L for each time t and plot a graph.
I've tried using ode23 and created a function. But it doesn't work. Any help in coding this in Matlab would greatly appreciated as I'm getting desperate! Thank you very much.

  2 件のコメント

Stephan
2019 年 10 月 21 日
Please attach what you have tried
Jon
2019 年 10 月 21 日
Before giving you advice advice about how to solve the problem using MATLAB I need to understand what is known and what is being solved for. You say the the load L is an output, so I assume that is unknown. Do you know U as a function of time? If so how is it specified. Do you have it defined by a function, or are you given values of U for specific values of time? You say that h is a displacement, so is the velocity U the rate of change (derivative with respect to time) of h?

サインイン to comment.

製品


リリース

R2018b

2 件の回答

Star Strider
回答者: Star Strider
2019 年 10 月 21 日
 採用された回答

You need to re-formulate your ‘first_order’ function. MATLAB derives a different set of equations:
syms A B h(t) L r U h0 Y
Eqn = diff(h,2) == 2/(U*r*B)*L + U*A + 0.6211*U*h/B;
[VF,Sbs] = odeToVectorField(Eqn)
first_order = matlabFunction(VF, 'Vars',{t,Y,A,B,L,r,U})
producing:
VF =
Y[2]
A*U + (6211*U*Y[1])/(10000*B) + (2*L)/(B*U*r)
Sbs =
h
Dh
first_order = @(t,Y,A,B,L,r,U)[Y(2);A.*U+(U.*Y(1).*6.211e-1)./B+(L.*2.0)./(B.*U.*r)];

  16 件のコメント

Star Strider
2019 年 10 月 24 日
Parameters by definition do not vary. If you specify a value for ‘h’ at a particular time ‘t’, you can likely solve for ‘L’ at those values of ‘h’ and ‘t’. Do you have values for ‘h’ and ‘t’ otherwise? (Note that in that event, ‘L’ becomes a variable, and not a parameter.)
Saruultugs Batzorig 2019 年 10 月 24 日
I see, L is a variable in that case. t being time goes from 0 to 100. I do not have values for h.
Star Strider
2019 年 10 月 24 日
To estimate ‘L’ as a function of ‘t’, you would need to provide values for ‘h(t)’. You could then solve for ‘L’.
Alternatively, you could re-formulate your differential equation in terms of . However this still leaves the problem of defining ‘h’, unless you reformulate it to eliminate ‘h’.
I have no idea what you are doing.

サインイン to comment.


Jon
回答者: Jon
2019 年 10 月 21 日
編集済み: Jon
2019 年 10 月 21 日

Your verbal problem description in which you call L and ouput, but in fact you know what it is, somewhat confuses me, but in anycase going from your equations I think I see what you are trying to do.
Besides the details of how to get extract the variables from what is returned by ode23, I think you have some more fundamental issues.
You are solving for dh/dt , but you want h. If you want h then you should set up a system of two first order ode's
So for example defining y1 = h, y2 = dh/dt
dydt = fun(t,y)
dydt = [y(2)
(2/(U.*r*B)).*L+U.*A+(U./B)*0.6211*y(1)];
Note that you can also use two left hand argument to ode23 and get the answers returned as y and t rather than in a structure if you prefer.
The additional arguments can be sent using the anonymous function as you did before as long as they are in the local workspace when you call ode23.
Sorry I see now that @Starstrider has been giving you additional ideas while I was writing this answer, but maybe this is helpful too.

  2 件のコメント

Saruultugs Batzorig 2019 年 10 月 21 日
Thank you for you answer, ultimately I'm trying to plot L against time t for the given equation with the said initial conditions.
Jon
2019 年 10 月 21 日
What exactly do you know, and what are you trying to solve for?
You can not solve for both L and h knowing only U as a function of time.
If you know h as a function of time and U as a function of time you could differenitate h twice then substitute for d2hdt in your function and solve for L as a function of time. (Not solving an ODE at all).
If you know L(t) as a function of time and U(t) as a function of time then you could use ode23 but you must include them within your dydt function. So just as an illustrative made up example if U(t) = sin(t) and L(t) = cos(t) you would have
dydt = fun(t,y)
U = sin(t);
L = cos(t)
dydt = fun(t,y)
dydt = [y(2)
(2/(U.*r*B)).*L+U.*A+(U./B)*0.6211*y(1)];

サインイン to comment.



Translated by