将 ode45() 转换为 scilab

Convert ode45() to scilab

我正在尝试将此脚本从 matlab 转换为 scilab。我尝试了 scilab 工具进行转换,但它崩溃了,没有输出,所以我是手工完成的。这是我通过将注释从 % 更改为 // 得到的结果。 @markovprocessfunc 指的是我能够使用 scilab 自动工具转换的另一个文件。

// Markovprocess
// Main program of the markovprocess simulation
// The system is defined by the generator matrix A
// Ulf Jeppsson, January 2017

global B

// Define the duration of the simulation
disp(' ')
disp('Automation 2017, Markov processes')
disp(' ')
tend = input('Set simulation time =  ');
disp(' ')

// Make a new simulation with the same A matrix?
yes = input('Keep the old A matrix? (yes=1, no=0)   ');
disp(' ')

if yes>0.9
    A
else
    disp('Provide the A generator matrix (on the form [ x x .. ;  x ...], or give the name of a predefined matrix in the Matlab workspace)')
    A = input('A = ')
end
// The generator matrix A is transposed to a matrix B 
B = A';

//define the initial condition p(0) (a row vector)
p = input('Define initial condition, p (row) vector (on the form [ x x .. ]) ');

// The row vector p is transposed to a column vector x0
x0 = p';

//Solve the differential equation
[t,x] = ode45(@markovprocessfunc,[0,tend],x0);

// Plot the results
plot(t,x)
grid on;
xlabel('Time')
ylabel('Probabilities')
m=length(A);
 if m==2
    legend('s1', 's2')
end
if m==3
    legend('s1', 's2','s3')
end
if m==4
    legend('s1', 's2','s3', 's4')
end
if m==5
    legend('s1', 's2','s3', 's4', 's5')
end
if m==6
    legend('s1', 's2','s3', 's4', 's5', 's6')
end
if m==7
    legend('s1', 's2','s3', 's4', 's5', 's6', 's7')
end
if m==8
    legend('s1', 's2','s3', 's4', 's5', 's6', 's7', 's8')
end
title('Markov Process')

m = size(A,1);
 aa = A';  //transpose the A matrix
 aa(m,:) = 1;  //add ones to the last column (can be any column), i.e. the sum all p(i) must equal 1
 b = zeros(m,1);  //create b-vector with zeros
 b(m)=1;  //add a 1 to the same row as where you added 1:s to the column of A
 c = aa\b;  //solve the linear equation system
 stationary_solution_vector = c'   //transpose the solution vector back to a row vector
 
 e_raised_to_A_times_1000 = expm(A*1000)
 eigenvalues_of_A = eig(A)'

我发现通过将行 [t,x] = ode45(@markovprocessfunc,[0,tend],x0); 替换为

t = [0 1 2 3]
x = [1 2 3 4]

脚本工作正常(但显然我得到了错误的结果)。那么如何将 ode45 转换为 scilab?我认为在我完成之后一切都会正常。

关于 mfile2sci() 代码转换器的崩溃,请不要犹豫,为您的用户案例 post 错误报告 @ https://bugzilla.scilab.org。如果不报告错误,事情就不会变得更好。

即使转换器没有崩溃,ode45() 指令也不会被转换。但它可能是(让我们把它放在我们的待办事项列表中;-)。实际上,相当于

[t,x] = ode45(@markovprocessfunc,[0,tend],x0);

n = 100;  // or whatever value you wish
t = linspace(0, tend, n);
x = ode("rkf", x0, t(1), t, markovprocessfunc);