楼主: peterboy
15710 9

[问答] R作函数图急问 [推广有奖]

  • 0关注
  • 0粉丝

已卖:356份资源

本科生

75%

还不是VIP/贵宾

-

威望
0
论坛币
432 个
通用积分
1.7082
学术水平
2 点
热心指数
3 点
信用等级
2 点
经验
1317 点
帖子
54
精华
0
在线时间
127 小时
注册时间
2010-3-24
最后登录
2017-12-25

楼主
peterboy 发表于 2011-8-7 21:34:10 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
x是一个包含49个数的数组 ,我想画出函数q,请问错在哪里?求高手指导!

ps其中T DT是已经定义好的函数

z=numeric(length(x))
q<-function(z)  1/49/0.1143*.075*sum((1-(T(z)-T(x))^2)*DT(z))

curve(q,from=10000,n=101)


Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
In addition: Warning message:
In T(z) - T(x) :
  longer object length is not a multiple of shorter object length




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:numeric length leng Eric NUM

一塌糊涂

搞毛啊

沙发
qoiqpwqr 发表于 2011-8-8 03:49:29
你的z的数值已经固定为49了,所以你的函数只有一个点。

藤椅
peterboy 发表于 2011-8-8 08:14:02
qoiqpwqr 发表于 2011-8-8 03:49
你的z的数值已经固定为49了,所以你的函数只有一个点。
> x
[1] 1371.00 7702.00 49.00 207.00 6655.00 206827.00
[7] 17064.00 4.00 72845.00 56545.00 2695.00 313.00
[13] 12498.00 24835.00 175254.00 2158500.00 602.00 2928.00
[19] 50984.00 593.00 6698.00 5075.00 44388.00 495.00
[25] 36935.00 23673.00 15179.00 281652.00 158713.00 77431.00
[31] 67388.00 25326.00 28433.00 32433.00 116355.00 460273.00
[37] 125209.00 184164.00 47380.00 146792.00 148449.00 14774.40
[43] 466041.00 94959.27 262810.80 79962.00 201922.06 85949594.00
[49] 273782.00
> T<-function(x){
+ m=44388
+ a=0.6714
+ c=0.0263
+ ((x+c)^a-c^a)/((x+c)^a+(m+c)^a-2*c^a)
+ }
>
>
> DT<-function(x){
+ m=44388
+ a=0.6714
+ c=0.0263
+ a*(x+c)^(a-1)*((m+c)^a-c^a)/((x+c)^a+(m+c)^a-2*c^a)^2
+ }
>
>
>
> q1<-function(z) 1/49/0.1143*.075/(0.75/0.1143-(1-3*T(z)^2-3*T(z))/4*0.1143^3)*sum((1-(T(z)-T(x))^2)*DT(z))
>
> q2<-function(z) 1/49/0.1143*.075/(0.75/0.1143*(1-T(z))-(1-3*T(z)^3)/4*0.1143^3+0.5)*sum((1-(T(z)-T(x))^2)*DT(z))
>
> q3<-function(z) 1/49/0.1143*.075*sum((1-(T(z)-T(x))^2)*DT(z))
>
> area=function(t) {
+ if(x<2104) area<-q1
+ else if (x>=2104&x<=936883) area<-q2
+ else area<-q3
+ }
> curve(area,0,10000000)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
In addition: Warning message:
In if (x < 2104) area <- q1 else if (x >= 2104 & x <= 936883) area <- q2 else area <- q3 :
the condition has length > 1 and only the first element will be used


万分感谢!那请问现在错误怎么改?。。。不知道哪个length不对。。。
一塌糊涂

搞毛啊

板凳
1good2girl 发表于 2011-8-8 11:27:48
area=function(t) {
if(x<2104) area<-q1
else if (x>=2104&x<=936883) area<-q2
else area<-q3
}
变量名不对,变量为x,x是个vector,所以循环语句判断x中元素的大小,修改以后的area为
area=function(x) {
for(i in length(x)){
   if(x[i]<2104) area<-q1
   else if ((x[i]>=2104)&&(x[i]<=936883)) area<-q2
   else area<-q3
   }
}
请验证

报纸
1good2girl 发表于 2011-8-8 11:31:39
不过画出来来是条直线,不知道什么含义

地板
peterboy 发表于 2011-8-8 19:26:16
额,多谢楼上两位,但是应该不是这样的。。。

q1 q2 q3是关于z多项式的函数,x是一维数组,仅仅是把它代入到q1 q2 q3式子里面

所以最后分段函数应该是分段连续的,我不知道怎么改。。。

另外顺便问下https://bbs.pinggu.org/forum.php? ... p;page=1#pid2304633
错在哪里?这个简单许多但同样错误。。。
一塌糊涂

搞毛啊

7
peterboy 发表于 2011-8-8 19:33:05
或者我用
curve(q1,0,2104)     //这个可以画出来
Warning message:
In T(z) - T(x) :
  longer object length is not a multiple of shorter object length

curve(q2,2104,936883,add=TRUE)  //画不出来了。。。
Warning message:
In T(z) - T(x) :
  longer object length is not a multiple of shorter object length


curve(q3,936883,1000000,add=TRUE)    //画不出来。。。

Error in xy.coords(x, y) : 'x' and 'y' lengths differ
In addition: Warning message:
In T(z) - T(x) :
  longer object length is not a multiple of shorter object length
一塌糊涂

搞毛啊

8
zhangyangsmith 发表于 2011-8-8 20:42:18
Probably you need to check the expression of the q1, q2 and q3 functions. It is not clear what you want to calculate, e.g.
> q1<-function(z) 1/49/0.1143*.075/(0.75/0.1143-(1-3*T(z)^2-3*T(z))/4*0.1143^3)*sum((1-(T(z)-T(x))^2)*DT(z))
q1 is supposed to be a function with one input variable, z. But you wrote T(z) - T(x). This expression is correct only if the dimension of z is the same of x. That's why you got the warining and errors.

9
peterboy 发表于 2011-8-8 23:10:51
zhangyangsmith 发表于 2011-8-8 20:42
Probably you need to check the expression of the q1, q2 and q3 functions. It is not clear what you w ...
你说的对,可能q1 q2 q3函数写错了。。。
我的本意是一个sigma求和函数,(T(x)-T(x1))*(T(x)-T(x2))*......*(T(x)-T(x49)) 这里x是自变量,相当于上面的z

请问我应该怎么改呢?
一塌糊涂

搞毛啊

10
zhangyangsmith 发表于 2011-8-9 05:30:03
Not quite sure what you want.

Use the original notation (i.e. z is function input, x is constant vector):

(T(z)-T(x[1]))*(T(z)-T(x[2]))*......*(T(z)-T(x[49])) =>
  1. prod(T(z) - T(x))
复制代码
(T(z) - T(x[1]))*(T(z) - T(x[1])) + (T(z) - T(x[2]))*(T(z) - T(x[2])) + ...... + (T(z) - T(x[49]))*(T(z) - T(x[49])) =>
  1. crossprod(T(z) - T(x))
复制代码

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 01:16