Solving first order differential equation

45 次查看(过去 30 天)
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 个评论
Jon
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?

请先登录,再进行评论。

采纳的回答

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 个评论
Saruultugs Batzorig
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
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.

请先登录,再进行评论。

更多回答(1 个)

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
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
Jon 2019-10-21
编辑: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)];

请先登录,再进行评论。

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by