R中二次方程的等高线图 [英] Contour plot for quadratic equation in R

查看:101
本文介绍了R中二次方程的等高线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R重新创建下图所示的轮廓图。
这是恒定糖浆损失随速度和压力而变化的轮廓图。

I'm trying to recreate contour plot shown in the picture below using R. It is a contour plot of constant syrup loss as a function of speed and pressure.

此示例使用的数据:

speed      = c(100,100,100,100,100,100,120,120,120,120,120,120,140,140,140,140,140,140)
pressure   = c(10,10,15,15,20,20,10,10,15,15,20,20,10,10,15,15,20,20)
syrup_loss = c(-35,-25,110,75,4,5,-45,-60,-10,30,-40,-30,-40,15,80,54,31,36)

使用该数据创建二次方程:

With that data quadratic equation was created:

model <- lm(syrup_loss~speed + pressure + speed^2 + pressure^2 + speed*pressure)
summary(model)

哪个给出:

z = 1217.30556-31.25625 * x + 86.01667 * y + 0.1291 * x ^ 2-2.87333 * y ^ 2 + 0.02875 * x * y

z = 1217.30556 - 31.25625*x + 86.01667*y + 0.1291*x^2 - 2.87333*y^2 + 0.02875*x*y

I t使用此代码创建轮廓图,但未给出可接受的结果:

I tried creating contour plot using this code, but it doesn't give acceptable result:

x = seq(100, 140, len=100)
y = seq( 10,  20, len=100)
z = outer(x, 1217.30556 - 31.25625*x + 86.01667*y + 0.1291*x^2 - 
             2.87333*y^2 + 0.02875*x*y)
contour(x, y, z, nlev=12)


推荐答案

外部函数中,缺少 Y 参数。代码

In the outer function, the Y argument is missing. The code

z <- outer(x, y, function(x, y) 1217.30556 - 31.25625*x + 86.01667*y + 0.1291*x^2  - 2.87333*y^2 + 0.02875*x*y) 

已固定问题。

这篇关于R中二次方程的等高线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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