I am getting the following error in my code: "Unrecognized function or variable 'f'. " How do I correct this error? someone can help me in this TIA.
Show older comments
Answers (1)
You're using f in line 1 while you don't define it until line 3.
Move line 1 to anywhere after but before use amp in line 11 -- I'd suggest it makes sense that it be line 10, the first calculation after all the inputs...
Code execution is purely linear -- just because the variable is defined somewhere in the code isn't enough; it must be defined in sequence of code execution before it is referenced.
Of course, calling a function that returns variables isn't strictly linear in execution in that the code in the function may be elsewhere in the function or another m-file or builtin, but the calling of the function must be in sequence such that any variables it defines (and returns) are available in order...
3 Comments
Walter Roberson
on 31 Jul 2021
I have encountered computer languages which permitted the statements in any order. The idea was that each assignment statement would be a pattern and that latter assignment statements would act to constrain the pattern. The solution at any one time would be the set of values such that all of assignment statements were satisfied. It was a strange way to think about programming, but it worked, in context.
However.... when you start to consider the statement
x = x + 1
then that statement would constrain x to the set of values such that the x did not change when you added 1 to it. That would restrict x to be one of:
* negative infinity
* positive infinity
* NaN (not a number)
* empty (adding something to emptiness results in emptiness)
So when designing computer languages you need to decide between systems in which the order of statements does not matter (because the result is whatever satisfies all of statements).... or procedural languages. If it is meaningful to say that you need to add 1 to a variable replacing the existing variable, then that is pretty much incompatible with a system in which you can put the statements in any order.
dpb
on 31 Jul 2021
"...computer languages which permitted the statements in any order." @Walter Roberson
Well, yes, but MATLAB is not one of those were so pretty-much a moot point here... :)
The input deck parser for many of the old nuclear design codes was designed the same way so that one make changes only to the original deck by substituting cards with the same sequence number with the new data for timesteps, say. A most handy innovation from Bettis Atomic Power Labs lo! those many years ago...
Walter Roberson
on 1 Aug 2021
The point was to talk about why computer languages do not work the way the poster was expecting, so that the poster would better understand the difficulty.
Categories
Find more on Characters and Strings 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!