如何通过初始化除一个之外的所有变量来绘制 R 中多个变量的函数 [英] How to plot function of multiple variables in R by initializing all variables but one
问题描述
通过给一些输入参数一个值来在二维图形中绘制多个变量的函数的最简单方法是什么.让我们考虑一个简单的例子
What's the easiest way to plot a function of multiple variables in a 2D graph by giving some of the input parameters a value. Let's consider a simple example
my.function<-function(a,b,x){a*x^2+b}
现在我想绘制简单的抛物线,其中 a=1
和 b=0
.所以我定义了一个新函数:new.function<-function(x){my.function(1,0,x)};情节(新功能)
.
Now I want to plot the simple parabola where a=1
an b=0
. So I define a new function:
new.function<-function(x){my.function(1,0,x)};
plot(new.function)
.
有什么方法可以在不定义 new.function
的情况下绘制函数?
Is there any way where I can plot the function without defining new.function
?
通常我使用 Mathematica,而在 Mathematica 中它会是:
Normally I use Mathematica and in Mathematica it would be:
绘图[my.function[1,0,x],{x ... }]
推荐答案
对于未来的读者,我在这里分享@G5W 的评论作为答案:
For future readers, I am sharing @G5W 's comment as answer in here:
plot(function(x) { my.function(1,0,x) })
我相信这是这里提供的最好的方法
I believe this is the best way of those provided in here
这篇关于如何通过初始化除一个之外的所有变量来绘制 R 中多个变量的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!