User request within a function
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am using a function to solve a coupled differential equation.
function [vec] = ode45func(x,z)
k = input('Value for k: ');
vec=[
z(1);
-4*z(1)-0.1*z(2)+k*(z(3)-z(1));
z(3);
-4*z(3)-0.1*z(4)+k*(z(1)-z(3))
];
end
As you can see, I try to get an user input when I call the function, to give k a value.
But I only get a loop of the input request. It just asks again and again for user input...
Any Ideas? Thank you
댓글 수: 0
채택된 답변
Steven Lord
2017년 6월 6일
The ODE solvers call the function you pass into them repeatedly. I suspect you want to ask for a value for k once at the start of the process of solving your ODE and to solve an ODE defined using that parameter value. If that's the case, don't include that in your ODE function. Parameterize your ODE function instead, asking for the value of k before you call ode45 and passing that into your ODE function as an additional parameter. The examples on that documentation page all use fzero, but the same techniques are also applicable for ode45.
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!