Integral vector .* sin(pi*x) error matrix dimensions must agree.

1 view (last 30 days)
I have the following code I try to find integral for function f the um is data vector (1X50). The problem is how can I used ingtral function to find integral for (vector .* sin(pi*x)), when I run code I received error "matrix dimensions must agree." any badoy can help me.
if true
L=1;
x = linspace(0, L, n);
fm=zeros(1,n);
for i=1:1
lam=i*pi;
f=@(x) um .* sin(lam * x ); % _um vector 1X50 double_
fm=fm+exp(lam^2*T)*sin(lam*x)*(2*integral(f,0,L));
end
end

Accepted Answer

Star Strider
Star Strider on 18 Oct 2018
When in doubt, and if you do not intend matrix operations, vectorise every operation to do element-wise operations. Specifying 'ArrayValued',true in the integral call is also necessary here.
Try this:
fm = fm + exp(lam^2*T).*sin(lam*x).*(2*integral(f,0,L, 'ArrayValued',1));

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!