undefined variable in a for cycle
显示 更早的评论
In this script (where function is a law of motion function=function(y,y',t)) I would like to find the response of the system varying the parameter 'omega'(included in the function as a force m*g*sin(omega*t))
[t,x]=ode45(@function,[0 0+dt],[0;0;0;0]);
plot(omega*ones(Nplot,1), x, '.', 'markersize', 2);
hold on;
I tried to write a for cycle like:
for w = 10:10:500
[t,x]=ode45(@function,[0 0+dt],[0;0;0;0]);
plot(omega*ones(Nplot,1), x, '.', 'markersize', 2);
hold on;
end,
but if I put omega as a variable of input for 'function' the error that appear is: ??? Input argument "omega" is undefined. how can i do?? thanks a lot!!
5 个评论
Never ever use the name function for any function or variable name. The words function is a very important inbuilt key-word, and it should not be shadowed like this. Doing this is going to cause all sorts of problems which you really want to avoid.
In any case you state "if I put omega as a variable of input for 'function'", but your code does not show this at all. How are you defining omega, and how are you providing it to your function?
Guido De Angelis
2015-7-16
Stephen23
2015-7-16
Sure, I understand that you want "omega" passed to the function. But nowhere outside or inside of the function is "omega" actually defined, so it is not clear if this should be a static constant or something else. Is "omega" supposed to be the loop variable?
Steven Lord
2015-7-16
Stephen: if you find it possible to create a variable named function or to call a function you've created that is named function, contact Technical Support immediately. The identifier "function" is a keyword, and with one exception (that doesn't apply to "function") you should NOT be able to define variables or call functions with the same name as a keyword.
Stephen23
2015-7-16
@Steven Lord: I have never tried... but that sounds like an interesting challenge :)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!