1
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);

I want to use all element "p" as polynomial coefficients. How to put all elements into an array?

1 Answer 1

1

There are two ways:

Option 1: Specify the amount of output parameters

[p1,p2,p3] = solve(S, A);
p1 = double(p1);
p2 = double(p2);
p3 = double(p3);

Option 2: Convert the output to an array using structfun

p = solve(S,A);
p = structfun(@double, p);

Result:

p =
     0
     3
     0
Sign up to request clarification or add additional context in comments.

1 Comment

There is a third way. "struct2array"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.