MATLAB: How do I pass a parameter to a function?

后端 未结 1 1486
野趣味
野趣味 2020-12-06 06:21

I have the following function:

function ypdiff = ypdiff(t,y)
    a = 0.01;
    b = 0.1;
    ypdiff(1) = -a*y(1)*y(2);
    ypdiff(2) = b*y(1)*y(2)-b*y(2);
            


        
相关标签:
1条回答
  • 2020-12-06 07:23

    You can use an anonymous function in matlab (similar to lambda functions in other languages):

    u = 1.2;
    [t y] = ode45(@(t, y) ypdiff(t, y, u), [to tf], yo);
    
    0 讨论(0)
提交回复
热议问题