一个mathematica程序添加作图语句
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/08/27 00:56:20
一个mathematica程序添加作图语句
Clear[x,y,n,h,S1,S2,S3,S4,i];
y[1] = 0; h = 0.1;
n = 100
Do[x[i] = 1.0 + (i - 1)*h,{i,1,n + 1}]
f[x_,y_] = 2.5-0.8 y;
Do[{S1 = f[x[i],y[i]],S2 = f[x[i] + h/2,y[i] + h*S1/2],
S3 = f[x[i] + h/2,y[i] + h*S2/2],S4 = f[x[i] + h,y[i] + h*S3],
y[i + 1] = y[i] + (S1 + 2 S2 + 2 S3 + S4)*h/6},{i,1,n}]
Do[Print[x[i]," ",y[i]],{i,1,n + 1}]
需要在后面做出图形,求问需要添加的语句.
Clear[x,y,n,h,S1,S2,S3,S4,i];
y[1] = 0; h = 0.1;
n = 100
Do[x[i] = 1.0 + (i - 1)*h,{i,1,n + 1}]
f[x_,y_] = 2.5-0.8 y;
Do[{S1 = f[x[i],y[i]],S2 = f[x[i] + h/2,y[i] + h*S1/2],
S3 = f[x[i] + h/2,y[i] + h*S2/2],S4 = f[x[i] + h,y[i] + h*S3],
y[i + 1] = y[i] + (S1 + 2 S2 + 2 S3 + S4)*h/6},{i,1,n}]
Do[Print[x[i]," ",y[i]],{i,1,n + 1}]
需要在后面做出图形,求问需要添加的语句.
你要是想画出 x 与 y 的图像可以用 ListPlot 函数,需要添加的语句如下:ListPlot[Table[{x[i], y[i]}, {i, n + 1}]]输出图像:
要想将点连接起来可以加上选项 Joined .
ListPlot[Table[{x[i], y[i]}, {i, n + 1}], Joined -> True]更多图像选项及细节调整,请参考函数 ListPlot 的用法及例子.
![](http://img.wesiedu.com/upload/5/3c/53cef7f8f13abd9d4520f6da8d0b92be.jpg)
ListPlot[Table[{x[i], y[i]}, {i, n + 1}], Joined -> True]更多图像选项及细节调整,请参考函数 ListPlot 的用法及例子.