syms x t
n=3; a=-1; b=1;
f=@(x) x;
k=@(x,t) x*t;
A=sym('a',[1 n]);
y(x)=A(1);
for i=1:n-1
y(x)=y(x)+A(1,i+1)*(x^i);
end
I(A)=int((y(x)-f-int(k*y(t),t,a,b))^2,x,a,b)
for i=1:n
S(i)=diff(I,A(1,i));
end
p=solve(S,A);
我想将所有元素“p”用作多项式系数。 如何将所有元素放入数组?
答案 0 :(得分:1)
有两种方法:
选项1:指定输出参数的数量
[p1,p2,p3] = solve(S, A);
p1 = double(p1);
p2 = double(p2);
p3 = double(p3);
选项2:使用structfun
p = solve(S,A);
p = structfun(@double, p);
结果:
p =
0
3
0