Error of Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-100. in Rhomberg Integration

조회 수: 2 (최근 30일)
Hi everyone.
When I run the code I got error
'Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-100.
How can I correct this? My main purpose is to graph f(u) from u=0 to u=1 using Romberg Equation.
.
u=linspace(0,1);
% f=@(x)sin(x);
f = @(x) (u.^3)*(x^.4*exp(x)/(exp(x)-1).^2);
% a = input('Enter lower limit, a: ');
% b = input('Enter upper limit, b: ');
% n = input('Enter no. of subintervals, n: ');
a=0;
b=1;
n=6;
h = b-a;
r = zeros(2,n+1);
r(1,1) = (f(a)+f(b))/2*h;
fprintf('\nRomberg integration table:\n');
fprintf('\n %11.8f\n\n', r(1,1));
for i = 2:n
sum = 0;
for k = 1:2^(i-2)
sum = sum+f(a+(k-0.5)*h);
end
r(2,1) = (r(1,1)+h*sum)/2;
for j = 2:i
l = 2^(2*(j-1));
r(2,j) = r(2,j-1)+(r(2,j-1)-r(1,j-1))/(l-1);
end
for k = 1:i
fprintf(' %11.8f',r(2,k));
end
fprintf('\n\n');
h = h/2;
for j = 1:i
r(1,j) = r(2,j);
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by