我想用scilab解决以下微分方程:
f(x)=sin(x);
初始值为x0 = 0,y0 = 0;
我试过的是这个:
// Define x
x0=0; y0=0;
xinc=0.001; xf=6; x=x0:xinc:xf;
// Define differential equation
deff('y=f(x)','y=sin(x)');
// Solve differential equation
ydiff=ode(y0,x0,x,y);
但是,我收到错误:
-->exec('C:\Users\Saaama\Desktop\sinx().sce', -1)
ydiff=ode(y0,x0,x,y);
!--error 4
Undefined variable: y
at line 9 of exec file called by :
exec('C:\Users\Saima\Desktop\sinx().sce', -1)
我也试过了
ydiff=ode(y0,x0,x,f);
我仍然在ode函数上得到相同的错误。
ode
期望一个函数接受参数时间和空间dotx=f(t,x)
,即使函数中没有使用时间。
但是从上下文来看,你认为x
是时间变量,因此问题是一个简单的求积。然后你需要使用
deff('doty=f(x,y)','doty=sin(x)');
或长形式
function doty=f(x,y)
doty=sin(x)
endfunction