[CODE]ຄິດໄລ່ສົມຜົນຂັ້ນສອງໜຶ່ງໂຕລັບດ້ວຍ MATLAB
ຄິດໄລ່ສົມຜົນຂັ້ນສອງໜຶ່ງໂຕລັບດ້ວຍ MATLAB
ຢາກຊອກຫາໃຈຜົນຂອງສົມຜົນ aX^2+bX+c
1 disp(‘Calculate aX^2+bX+c’);
2 a = input(‘Enter “a” value =’);
3 b = input(‘Enter “b” value =’);
4 c = input(‘Enter “c” value =’);
5 delta = (b^2)–(4*a*c);
6 if delta < 0;
7 disp(‘No Answer’);
8 break; 9 end10 fprintf(‘delta = %.2f\n’,delta);
11 squareroot_delta = sqrt(delta);
12 fprintf(‘squaretoot delta = %.2f\n’,squareroot_delta);
13 if delta > 0;
14 x1 = (–b)–(squareroot_delta)/2*a;
15 x2 = (–b)+(squareroot_delta)/2*a;
16 fprintf(‘X1 = %.2f\n’,x1);
17 fprintf(‘X2 = %.2f\n’,x2);
18 else if delta == 0;
19 x = –b/2*a;
20 fprintf(‘X = %.2f\n’,x);
21 end
22 end