I know that the input syntax in scilab looks like this:
result = input ("Enter your number: ")
My problem is, how can I enter a function like cos(x) + sin(x) ?
Let the user enter a string (parameter "s" of the input
command), and use this string in eval
command for evaluation. Example:
fstr = input("Enter a function of x: ", "s")
x = input("What is the value of x: ")
y = eval(fstr)
disp("The value of function is " + string(y))
The string evaluation can be wrapped as a Scilab function, too:
fstr = input("Enter a function of x: ", "s")
function y = f(x)
y=eval(fstr)
endfunction
t = linspace(0, 2)
plot(t, f(t))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments