matlab中假设t=0:0.1:2*pi;为什么y=t.*sin(t).*sin(t)不等于y=t.*(sin(t))^2呢?

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 16:30:14
matlab中假设t=0:0.1:2*pi;为什么y=t.*sin(t).*sin(t)不等于y=t.*(sin(t))^2呢?

matlab中假设t=0:0.1:2*pi;为什么y=t.*sin(t).*sin(t)不等于y=t.*(sin(t))^2呢?
matlab中假设t=0:0.1:2*pi;为什么y=t.*sin(t).*sin(t)不等于y=t.*(sin(t))^2呢?

matlab中假设t=0:0.1:2*pi;为什么y=t.*sin(t).*sin(t)不等于y=t.*(sin(t))^2呢?
y=t.*sin(t).*sin(t)在理论上和y=t.*(sin(t)).^2得到的结果是一样的,但由于浮点数运算误差的关系,两者可能会存在一个非常微小的误差

结果是这样的,你可以再试一遍
>> t=0:0.1:2*pi;
y=t.*sin(t).^2
y =
Columns 1 through 8
0 0.0010 0.0079 0.0262 0.0607 0.1149 0.1913 0.2905
Columns 9 through 16...

全部展开

结果是这样的,你可以再试一遍
>> t=0:0.1:2*pi;
y=t.*sin(t).^2
y =
Columns 1 through 8
0 0.0010 0.0079 0.0262 0.0607 0.1149 0.1913 0.2905
Columns 9 through 16
0.4117 0.5522 0.7081 0.8737 1.0424 1.2070 1.3596 1.4925
Columns 17 through 24
1.5986 1.6718 1.7071 1.7014 1.6536 1.5648 1.4381 1.2790
Columns 25 through 32
1.0950 0.8954 0.6909 0.4932 0.3142 0.1660 0.0597 0.0054
Columns 33 through 40
0.0109 0.0821 0.2220 0.4307 0.7050 1.0387 1.4226 1.8448
Columns 41 through 48
2.2910 2.7453 3.1905 3.6092 3.9844 4.3000 4.5421 4.6993
Columns 49 through 56
4.7633 4.7295 4.5977 4.3714 4.0586 3.6711 3.2247 2.7378
Columns 57 through 63
2.2316 1.7286 1.2520 0.8247 0.4684 0.2024 0.0428
>>

收起

t=0:0.1:2*pi; %0到2π以0.1为间隔取值如0 0.1 0.2 0.3 ...2π
y=sin(t);
plot(t,y)%t的值为横坐标,y的值为纵坐标画图