您好,我是 MATLAB 新手,我想知道如何将我的字符串变成函数。我想以标准 Matlab 格式(例如exp(-10*X)-sin(pi*X)-2*tanh(X)
)从用户那里以字符串的形式访问函数,这里 X 是变量。然后我想用 'low' 和 'high' 变量替换 'X' 来计算这些限制下的函数值。为此,我使用了“strrep”。我收到以下错误 1) 未定义的函数或变量“X”。2) 我看不到“X”是否被“低”和“高”取代。
任何帮助将不胜感激。下面是我的代码。
high=input('Upper Limit of the Interval : ');
low=input('\nLower Limit of the interval : ');
usr_funct=input('Enter The Function in standard Matlab Format.\nEnter "X" for the
variable and * for multiply \n'); % Example exp(-10*X)-sin(pi*X)-2*tanh(X);
middle = (low+high)/2;
Flow =strrep(usr_funct, 'X', 'low');
Fhigh =strrep(usr_funct, 'X', 'high');
sprintf('Flow '); % This was to check if 'X' was replaced with 'low'. It is not printing anything