> P=makeFun(7.5*(4.1-0.5*cos(x))/(0.5*sin(x))~x)
> D(P(x)~x)
Error in cos(x) : non-numeric argument to mathematical function
I've been trying to create a function and it's giving me an error. I've tried a bunch of things with this function, and none of them work. I can plug a number into P, but I can't take it's derivative. What am I doing wrong?
我一直在尝试创建一个函数,它给了我一个错误。我用这个函数尝试了很多东西,没有一个是有效的。我可以把一个数字代入P,但我不能求它的导数。我做错了什么?
1 个解决方案
#1
1
Well, that was amusing. First I discovered that the package name is mosaic
, not Mosaic. After loading it and looking at the ?D page, I get no error:
嗯,那是有趣的。首先我发现包的名字是马赛克,不是马赛克。加载并查看D页后,我没有错误:
install.packages("mosaic", dependencies=TRUE)
load(mosaic)
P=makeFun(7.5*(4.1-0.5*cos(x))/(0.5*sin(x))~x)
D(P(x)~x)
#--------
function (x)
7.5 * (0.5 * sin((x)))/(0.5 * sin((x))) - 7.5 * (4.1 - 0.5 *
cos((x))) * (0.5 * cos((x)))/(0.5 * sin((x)))^2
You should now try to debug the problem by first determining if all the dependencies for the package available. I also had no object named "x" in my workspace, so you may wnat to execute `rm(x) and try re-running, since it appears that the evaluator is finding an "x" it doesn't like. (But I was not able to create that error by assigning a character value to 'x'.) I'm on a Mac running 3.1.0 Patched.
现在,您应该尝试调试这个问题,首先确定包的所有依赖项是否可用。在我的工作空间中,我也没有命名为“x”的对象,所以您可以执行“rm(x)”并尝试重新运行,因为它似乎是在寻找一个“x”它不喜欢的“x”。(但我无法通过将一个字符值赋给“x”来创建这个错误。)我在Mac上运行3.1.0补丁。
#1
1
Well, that was amusing. First I discovered that the package name is mosaic
, not Mosaic. After loading it and looking at the ?D page, I get no error:
嗯,那是有趣的。首先我发现包的名字是马赛克,不是马赛克。加载并查看D页后,我没有错误:
install.packages("mosaic", dependencies=TRUE)
load(mosaic)
P=makeFun(7.5*(4.1-0.5*cos(x))/(0.5*sin(x))~x)
D(P(x)~x)
#--------
function (x)
7.5 * (0.5 * sin((x)))/(0.5 * sin((x))) - 7.5 * (4.1 - 0.5 *
cos((x))) * (0.5 * cos((x)))/(0.5 * sin((x)))^2
You should now try to debug the problem by first determining if all the dependencies for the package available. I also had no object named "x" in my workspace, so you may wnat to execute `rm(x) and try re-running, since it appears that the evaluator is finding an "x" it doesn't like. (But I was not able to create that error by assigning a character value to 'x'.) I'm on a Mac running 3.1.0 Patched.
现在,您应该尝试调试这个问题,首先确定包的所有依赖项是否可用。在我的工作空间中,我也没有命名为“x”的对象,所以您可以执行“rm(x)”并尝试重新运行,因为它似乎是在寻找一个“x”它不喜欢的“x”。(但我无法通过将一个字符值赋给“x”来创建这个错误。)我在Mac上运行3.1.0补丁。