function programmation () string f Make$f wave w= f variable a,b,c,x
a=1
b=2
c=-1
f[x]=a*(x*x)+b*x+c for(x=5;x<10;x+=1) printx, f[x] endfor end
Several issues:
* Use indentation for structuring, the code is easier to read and to debug.
* f is an empty string. This cannot be converted to a wave reference (the "$").
* Again Make/O
* Please read the manual about wave indexing carefully. You will discover that
* x is a very bad choice for a variable name, especially for an index
* f is a string (foot note: characters can be accessed via [], hence no compiling error here -- but that is not what you want to do!) the wave is called w
* the assignment should be in the loop here --- BUT: please read the manual about wave indexing (yes mentioned twice): you will end up with something like w=a*p^2+b*p+c outside your loop again at this point
* please read the chapter about wave scaling. Now you probably want to write w=a*x^2+b*x+c, as well outside the loop
Please note the color of x and p versus of a, b, and c in the tagged text above!
Please run
displayhelptopic"The Waveform Model of Data" displayhelptopic"The XY Model of Data" displayhelptopic"Changing Dimension and Data Scaling" displayhelptopic"Waveform Arithmetic and Assignment"
string f
Make $f
wave w= f
variable a,b,c,x
a=1
b=2
c=-1
f[x]=a*(x*x)+b*x+c
for (x=5;x<10;x+=1)
print x, f[x]
endfor
end
Several issues:
* Use indentation for structuring, the code is easier to read and to debug.
*
f
is an empty string. This cannot be converted to a wave reference (the "$
").* Again
Make /O
* Please read the manual about wave indexing carefully. You will discover that
*
x
is a very bad choice for a variable name, especially for an index*
f
is a string (foot note: characters can be accessed via[]
, hence no compiling error here -- but that is not what you want to do!) the wave is calledw
* the assignment should be in the loop here --- BUT: please read the manual about wave indexing (yes mentioned twice): you will end up with something like
w=a*p^2+b*p+c
outside your loop again at this point* please read the chapter about wave scaling. Now you probably want to write
w=a*x^2+b*x+c
, as well outside the loopPlease note the color of x and p versus of a, b, and c in the tagged text above!
Please run
displayhelptopic "The XY Model of Data"
displayhelptopic "Changing Dimension and Data Scaling"
displayhelptopic "Waveform Arithmetic and Assignment"
from the command line ( ctrl-j ) one by one.
HJ
February 2, 2017 at 07:19 am - Permalink