这个函数怎么不对呀
a1 =8977; b1 = -1.027e+004;c1 = 4543 ;a2 =170.2; b2 =1.077e+004; c2 =1.012e+004;
a3 =159.8; b3 =2.602e+004; c3 = 1.41e+004;
a4 =188.1; b4 = 757.5; c4 = 6809;
a5 =128.5; b5 =4.579e+004; c5 = 1.84e+004;
a6 = 157; b6 =7.577e+004; c6 =2.903e+004;
a7 = 162.9 ; b7 =1.635e+005 ; c7 =3.864e+004;
a8 = 106.4 ; b8 = 1.15e+005; c8 =3.413e+004;
f(x) = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2) + a3*exp(-((x-b3)/c3)^2) + a4*exp(-((x-b4)/c4)^2) +a5*exp(-((x-b5)/c5)^2) + a6*exp(-((x-b6)/c6)^2) + a7*exp(-((x-b7)/c7)^2) + a8*exp(-((x-b8)/c8)^2);
[ 本帖最后由 ChaChing 于 2009-4-28 15:42 编辑 ]
回复 楼主 baolaoer 的帖子
f(x)=a*x+bmatlab没有这种语法。函数的定义不是这样的,请参照matlab教科书。 syms x;
f=f(x) = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2) + a3*exp(-((x-b3)/c3)^2) + a4*exp(-((x-b4)/c4)^2) +a5*exp(-((x-b5)/c5)^2) + a6*exp(-((x-b6)/c6)^2) + a7*exp(-((x-b7)/c7)^2) + a8*exp(-((x-b8)/c8)^2);
这样再看看!!
>> syms x;
>> a1 =8977; b1 = -1.027e+004; c1 = 4543 ;
a2 = 170.2; b2 =1.077e+004; c2 =1.012e+004 ;
a3 = 159.8; b3 =2.602e+004; c3 = 1.41e+004;
a4 = 188.1 ;b4 = 757.5; c4 = 6809;
a5 = 128.5; b5 =4.579e+004; c5 = 1.84e+004;
a6 = 157;b6 =7.577e+004; c6 =2.903e+004;
a7 = 162.9 ; b7 =1.635e+005 ; c7 =3.864e+004;
a8 = 106.4 ; b8 = 1.15e+005; c8 =3.413e+004;
>> f= a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2) + a3*exp(-((x-b3)/c3)^2) + a4*exp(-((x-b4)/c4)^2) +a5*exp(-((x-b5)/c5)^2) + a6*exp(-((x-b6)/c6)^2) + a7*exp(-((x-b7)/c7)^2) + a8*exp(-((x-b8)/c8)^2);
>> pretty(f)
/ 10270\2 / 1077\2
8977 exp(-|1/4543 x + -----| ) + 851/5 exp(-|1/10120 x - ----| )
\ 4543 / \ 1012/
/ 1301\2 1881 / 1515 \2
+ 799/5 exp(-|1/14100 x - ----| ) + ---- exp(-|1/6809 x - -----| )
\ 705 / 10 \ 13618/
/ 4579\2 / 7577\2
+ 257/2 exp(-|1/18400 x - ----| ) + 157 exp(-|1/29030 x - ----| )
\ 1840/ \ 2903/
1629 / 2725\2 / 11500\2
+ ---- exp(-|1/38640 x - ----| ) + 532/5 exp(-|1/34130 x - -----| )
10 \ 644 / \ 3413 /
简化以后的
ff=simplify(f);
>> pretty(ff)
2 2
8977 exp(- 1/20638849 (x + 10270) ) + 851/5 exp(- 1/102414400 (x - 10770) )
2
+ 799/5 exp(- 1/198810000 (x - 26020) )
1881 2
+ ---- exp(- 1/185449924 (2 x - 1515) )
10
2
+ 257/2 exp(- 1/338560000 (x - 45790) )
2
+ 157 exp(- 1/842740900 (x - 75770) )
1629 2
+ ---- exp(- 1/1493049600 (x - 163500) )
10
2
+ 532/5 exp(- 1/1164856900 (x - 115000) )
[ 本帖最后由 ChaChing 于 2009-4-28 21:21 编辑 ] 也可以做成一个m程序文件
function ff=myfunction(x)
a1 =8977; b1 = -1.027e+004;c1 = 4543 ;
a2 =170.2; b2 =1.077e+004; c2 =1.012e+004;
a3 =159.8; b3 =2.602e+004; c3 = 1.41e+004;
a4 =188.1; b4 = 757.5; c4 = 6809;
a5 =128.5; b5 =4.579e+004; c5 = 1.84e+004;
a6 = 157; b6 =7.577e+004; c6 =2.903e+004;
a7 = 162.9 ; b7 =1.635e+005 ; c7 =3.864e+004;
a8 = 106.4 ; b8 = 1.15e+005; c8 =3.413e+004;
ff= a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2) + a3*exp(-((x-b3)/c3)^2) + a4*exp(-((x-b4)/c4)^2) +a5*exp(-((x-b5)/c5)^2) + a6*exp(-((x-b6)/c6)^2) + a7*exp(-((x-b7)/c7)^2) + a8*exp(-((x-b8)/c8)^2);
运行后>> myfunction(2)
ans =
300.4596
>>
[ 本帖最后由 ChaChing 于 2009-4-28 21:22 编辑 ]
回复 沙发 sogooda 的帖子
我记得matlab好像可以这么定义,但是忘记是哪个函数了。。。。回复 5楼 波波球 的帖子
你是说这种吗?a=1;b=1;
f=@(x)a*x+b 匿名函数。。。
页:
[1]