undefined variable in a for cycle
Show older comments
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 Comments
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
on 16 Jul 2015
Stephen23
on 16 Jul 2015
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
on 16 Jul 2015
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
on 16 Jul 2015
@Steven Lord: I have never tried... but that sounds like an interesting challenge :)
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!