评估符号功能 [英] Evaluating a symbolic function

查看:105
本文介绍了评估符号功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到cos(5).为什么此表达式无效:

I want to find cos(5). Why is this expression invalid:

syms x
f=sin(x)
disp(diff(f)(5))

错误是

Line: 3 Column: 12
Indexing with parentheses '()' must appear as the last operation of a valid indexing expression.

推荐答案

您的错误与符号变量无关.

Your error has nothing to do with symbolic variables.

这是由语句diff(f)(5)引起的-这不是MATLAB 语法允许的(自R2019b起). MATLAB将此解释为用户尝试访问某个中间结果的第5个元素.如果要了解x=5x=5f的导数的实际值,则必须替换所需的x值(使用subs)并将其转换为某种数字格式(例如):

It is caused by the statement diff(f)(5) - which is not something MATLAB syntax allows (as of R2019b). MATLAB interprets this as the user trying to access the 5th element of some intermediate result. If you want to know the actual value of the derivative of f at x=5, you would have to substitute the desired value of x (using subs) and convert this to some numeric format (such as double):

syms x
f = sin(x)
disp(double(subs(diff(f),x,5))) % substitute x and convert to double

这篇关于评估符号功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆