I have in my simulation 3 fields. The first one has the function (for example 4*sin(pi/8*x)) but it can change from the user. The second one has the x-value of the function which also could be defined by the user. The third one is not editable and should show the value of the function.
By the initialization page when I write fx = _view.functionField.evaluate({x:1}); I get the correct result for x=1 but I want to get a result for any x given by the user in the second field.
I have tried fx = _view.functionField.evaluate({x:_view.xField}); (xField is the name of my 2nd field) but it doesn't work.
Can anyone help me make this working? Thank you!!!!
Where are you evaluating the function? You should evaluate the function in the Fixed Relation page and assign the value into a global variable that is bound to a numeric field. Here is an example for how to evaluate the function field.
The example "One Dimensional Wave Superposition JS Model" didn't help me a lot because I want to have a field with the calculated value of the function. If you could see the files I attached maybe you can spot my mistake.
The SinusFunction file is my first approach but I don't know what to do by ft = _view.functionField.evaluate({t:1}); so as to calculate the value from my tField. The plot works ok here.
The SinusFunction2 file is what I did based on your suggestion. With the changes I made now the plot doesn't work properly when I change the values of tmin or tmax. So I think I made it worse...
Mirka- You are making this much too hard. Code in a Fixed Relation page is evaluated whenever anything in the model changes. All you need to do is to evaluate the function string in a Fixed Relation. Your global variable "ft" will then show the correct value in the output field. You do not need to re-plot the entire graph using _initialization to show only a single value. See the attached example.
When sending source files, use the build in "Zip the simulation source files" option when right-clicking on the package icon to package all the source files. Do not use an external program, such as rar, to package the files.