无法使用Scilab正确解决ODE问题

问题描述 投票:2回答:1

我想用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 scilab
1个回答
2
投票

ode期望一个函数接受参数时间和空间dotx=f(t,x),即使函数中没有使用时间。

但是从上下文来看,你认为x是时间变量,因此问题是一个简单的求积。然后你需要使用

deff('doty=f(x,y)','doty=sin(x)');

或长形式

function doty=f(x,y)
    doty=sin(x)
endfunction
© www.soinside.com 2019 - 2024. All rights reserved.