Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wolfram mathematica 用Mathematica绘制方程的解_Wolfram Mathematica - Fatal编程技术网

Wolfram mathematica 用Mathematica绘制方程的解

Wolfram mathematica 用Mathematica绘制方程的解,wolfram-mathematica,Wolfram Mathematica,我有一个函数f(x,t),我想用Mathematica绘制f(x(t),t)=0的解的函数x(t)。我怎么做 Mathematica通常与我可以使用的其他编程语言非常不同。通常情况下,我会尝试类似于: Create arrays X, T For t in T do solve (numerically) f(x,t)=0, append the solution to X Plot X 然而,我还不知道如何在Mathematica中使用循环,数组也是如此,所以我在这方面遇到了严重的

我有一个函数
f(x,t)
,我想用Mathematica绘制
f(x(t),t)=0的解的函数
x(t)
。我怎么做

Mathematica通常与我可以使用的其他编程语言非常不同。通常情况下,我会尝试类似于:

Create arrays X, T

For t in T do
   solve (numerically) f(x,t)=0, append the solution to X

Plot X
然而,我还不知道如何在Mathematica中使用循环,数组也是如此,所以我在这方面遇到了严重的问题

用Mathematica有没有快速、直接的方法来解决这个问题?如果没有,有人能帮我解决这个问题吗

还有,有人对这个问题有更好的标题吗


编辑:根据@LutzL的建议,我将尝试以下方法:

Table[FindRoot[f[x,t]==0,{x,x_0}],{t,start,stop,step}]
这是否正确

我仍然有一个问题,因为我的函数
f(x,t)
是高度非线性的,因此我想为每个
t
输入一个好的起点。具体地说,我知道
t=0的解决方案,我想使用
t{n+1}
的时间步长
t\n
的解决方案。有办法做到这一点吗


编辑2:我用以下方法解决了问题:

tmax = 10; nsteps = 100*tmax;
thrust = {v/2 - g}; angle = {Pi/2};
For[i = 1, i <= nsteps, i++, 
  sol = {thr, \[Theta]} /. 
    FindRoot[{eq1[i*tmax/nsteps], 
      eq2[i*tmax/nsteps]}, {{thr, Last[thrust]}, {\[Theta], 
       Last[angle]}}]; AppendTo[thrust, sol[[1]]]; 
  AppendTo[angle, sol[[2]]]];
ListPlot[Table[{i*tmax/nsteps, thrust[[i + 1]]}, {i, 0, nsteps}]]
ListPlot[Table[{i*tmax/nsteps, angle[[i + 1]]/Pi}, {i, 0, nsteps}]]
tmax=10;nsteps=100*tmax;
推力={v/2-g};角度={Pi/2};

对于[i=1,i一种方法是创建一个列表,然后绘制它

您有
x(0)
,并且您想要
x(t)表示t>0
。您可以使用Szabolcs提供的表达式:

root(t_NumericQ, x0_):= Module[{z}, z = z /. FindRoot[f[z, t] == 0, {z, x0}]]
然后计算并绘制一个列表

list[tin_, tend_, tstep_, x0_] := Module[{z = x0, t = tin}, lis = {}; 
While[t < tend, z = root[t, z]; lis = Append[lis, {t, z}]; t = t + tstep; ];
ListPlot[lis]]
list[tin,tend,tstep,x0]:=Module[{z=x0,t=tin},lis={};
而[t
或者您可以更改
x=Interpolation[lis]
的最后一行,
x[t]
将是解决方案
x(t)


此外,您还可以测试
x(t)
的其他解决方案是否可以替代
RandomReal[{x_1,x_2}]
root[t,z]
,其中
x_1
x_2
在您想要探索的
x
空间范围内。

您只需绘制f(x,t)的水平集即可在等高线图中。有选项可以控制绘制哪些标高,因此f(x,t)的图=0是可以保证的。@LutzL这里的问题是
x
是一个向量,所以这样做会很麻烦。无论如何,谢谢你的好主意。然后我会考虑使用table命令和数值解算器构建一个解算点数组。@LutzL我用
table
编辑了我的答案。我仍然有一个解决方案小问题。你还有什么建议吗?Mathematica是一种基于术语重写的函数式语言,它与Python或C有很大的不同。它非常强大,一旦你学好了,你就可以用很少的代码快速实现。但首先你必须学会如何用Mma的方式而不是强制实现这是一个你想要的例子:
f[a?NumericQ]:=Module[{x},x/.FindRoot[Log[a x]==Sin[x],{x,1}];Plot[f[a],{a,0.1,10}]
谢谢!我提出了我如何解决问题的问题,但我必须说我的方式看起来比你的方式更难看。噢!我没有看到你上次的编辑。我现在来看看。另一件有趣的事情是寻找额外的解决方案。。