Unwanted Exponential output in matlab calculation

1 次查看(过去 30 天)
Hi All I am solving multiple regression problem using vectors entered at run time. Some of the output variables default to exponential format and inspection with manual cal shows they're wrong. I underestimated it; spent all day yesterday to fix it without success hence I am sharing it. I've commented on the wrong outputs below. Thanks, in advance.
x1 = input('Enter x1 data:');
x2 = input('Enter x2 data:');
y = input('Enter y data:');
a = mean(x1);b= mean(x2);c = mean(y);
mean_of_x1 = a
mean_of_x2 = b
mean_of_y = c
table =[y; x1; x2; y-c; (y-c).^2; x1-a; x2-b;(x1-a).*(x2-b);(x1-a).^2;(x2-b).^2; (x1-a).*(y-c);(x2-b).*(y-c)];
fprintf('y, x1, x2, y-c, (y-c).^2, x1-a, x2-b, (x1-a).*(x2-b), (x1-a).^2, (x2-b).^2, (x1-a).*(y-c),(x1-a).*(y-c);(x2-b).*(y-c)\n ')
fprintf('%4.2f %8.2f %10.2f %12.2f %14.2f %16.2f %18.2f %20.2f %22.2f %24.2f %26.2f %28.2f\n', table)
summation_of_x1 = sum(x1)
summation_of_x2= sum(x2)
summation_of_y = sum(y)
d = y-c;
summation_of_y_minus_C = sum(d)% THIS DEFAULTS TO EXPONENTIAL EVEN WITH 'SMALL DATA'
summaion_of_y_minus_c_square=sum((y-c).^2)
e = x1-a;
summation_of_x1_minus_A=sum(e)
f = x2-b ;
summation_of_x2_minus_B = sum(f)% THIS ALSO DEFAULTS TO EXPO
sumation_of_product_x1_minus_A_and_x2_minus_B = sum((x1-a).*(x2-b))
Summation_x1_minus_A_square= sum((x1-a).^2)
Summation_x2_minus_B_Square= sum((x2-b).^2)
summation_product_x1_minus_A_and_y_mnius_c = sum((x1-a).*(y-c))
sumation_product_x2_minus_B_and_y_minus_c = sum((x2-b).*(y-c))
x1=[3, 1, 9, 5, 2]; x2=[12, 5, 11, 22, 3]; y=[28,9, 5, 7, 32]% My test data I've used many times without success

回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by