Output argument "dydt" (and maybe others) not assigned during call
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone,
I am trying to solve a second order differential equation, after finding the first orders using odeToVectorField. I have created the function below;
function dydt = first_order_conversion_two_eqn(t,V)
load('Standard_European_Bump_Data')
syms Z
syms t
syms Z(t)
syms theta
syms theta(t)
syms Kf
syms Kr
syms p
syms b
syms M
syms I
eqn1 = diff(Z(t),t,2)
eqn2 = diff(theta(t),t,2)
eqn3 = (-(Kf+Kr)*Z - Kf*(p-b)*theta + Kr*b*theta)/M
eqn4 = (-Kf*(p-b)*Z + Kr*b*Z - Kf*((p-b)^2)*theta - Kr*(b^2)*theta)/I
eqn5 = eqn1 == eqn3
eqn6 = eqn2 == eqn4
eqns = [eqn5, eqn6]
V = odeToVectorField(eqns)
end
and then tried to solve it using ode15s, by using the code below;
tspan = [0 20]
y0 = [0.1 0.5 0.3 0.8]
[t,V]=ode15s(@first_order_conversion_two_eqn, tspan, y0)
but when i try to solve it, it gives the following error;
Output argument "dydt" (and maybe others) not assigned during call to "first_order_conversion_two_eqn".
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in odeToVectorField_Solver (line 4)
[t,V]=ode15s(@first_order_conversion_two_eqn, tspan, y0)
I'm sure it's something very simple that i am missing, but i am very new to the ODE solvers and i cant see anything in the documentation that corresponds to args or varargin.
Any help would be appreciated, even if it's telling me where to look!
Thanks
Ross
댓글 수: 0
채택된 답변
Stephen23
2018년 3월 10일
편집: Stephen23
2018년 3월 10일
The problem has nothing to do with the ODE solver, it is because of how you defined your function like this:
function dydt = first_order_conversion_two_eqn(t,V)
But then nowhere inside that function do you define a variable called dydt. If you want to return the variable dydt then you need to define what it is:
function dydt = first_order_conversion_two_eqn(t,V)
...
dydt = ???
end
However your function has other problems: you never use the input arguments, so calling the ODE solver might not be doing what you expect it to do, and the load call (which is very slow) should be moved outside the function and the data passed as a third input argument:
S = load(...);
fun = @(t,y)@first_order_conversion_two_eqn(t,y,S);
[t,V] = ode15s(fun, tspan, y0)
where the function has been changed to have three inputs:
function dydt = first_order_conversion_two_eqn(t,y,S)
댓글 수: 2
Stephen23
2018년 3월 10일
편집: Stephen23
2018년 3월 10일
@Ross Hanna: the best place to learn how to use the ODE function is in the documentation: I would suggest that you try some of the (working) examples from the documentation, to get comfortable using the ODE solvers:
and of course be reading the help of the function that you are using:
Your function has two inputs, t and V, but you never use V (and possibly t) inside the function: this is what I meant by "you never use the input arguments". Notice how all of the examples in the documentation use both inputs arguments within the function (typically named t and y, as these are standard terms when defining a simple ODE).
I suspect your use of symbolic operations inside the ODE is also causing problems, but I have no experience of doing this so I cannot give any advice on how to do this properly. Using symbolic operations inside the function will slow the ODE solver down quite a lot, and should be avoided unless strictly required. I don't see anything there that requires using symbolic operations.
Does odeToVectorField return a column vector suitable for using with the ODE solvers?
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!