我试图在MATLAB 2017a中集成一个常量函数,但我被卡住了.首先,当我使用以下脚本进行集成时,我得到了正确的输出.所以脚本适用于x0依赖的脚本t.
function E=sol(n,k)
x0 = @(t) t^(2);
j = 0;
E = zeros(n,1);
while j < n+1 ;
K = matlabFunction(subs(po(j,k))) ;
eval(sprintf('x%d = integral(K,0,1);',j+1)) ;
E(j+1,1) = subs(sprintf('x%d',j+1))
j = j+1;
end
end
Run Code Online (Sandbox Code Playgroud)
功能po(j,k)如下,
function A_j = po(j,k) % Adomian polynomials
if j >0
x = sym('x',[1 j]);
syms p; % Assinging a symbolic variable for p
syms x0;
S = x0+ sum(p.^(1:j) .* x) ; % Sum of p*x up to …Run Code Online (Sandbox Code Playgroud)