Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

For SUT

Project: Matlab61
Views: 42
Kernel: Octave

Problems from pages 83 - 86
1, 3, 5, 12, and 13

เฉลย week 1&2 https://github.com/adadesions/Octave61

Problem 1

function area = triangle(a, b, c) p = a + b + c; s = p/2; A = sqrt(s*(s-a)*(s-b)*(s-c)); area = A; end
triangle(3, 4, 5)
ans = 6

Problem 3

function c = f2c() f = input("Enter a fahrenheite:"); c = 0.556*(f-32); fprintf("The temperature in Celsius is: %.2f", c); end
f2c();

Prblem 5 (ก)

% Mathematical Method sum51 = 0; for i = 1:15 sum51 += (-1)^(i+1)*i^2; end fprintf("Maths Method = %d\n", sum51); % Programming Method sum51p = 0; for i = 1:15 if mod(i, 2) == 0 % Evne number sum51p += -1*i^2; else sum51p += i^2; end end fprintf("Programming Method = %d\n", sum51p);
Maths Method = 120 Programming Method = 120

Problem 5(ข)

sum52 = 0; for i = 0:14 sum52 += 1/(2*i+1); end fprintf("Summation of 5.2: %.3f\n", sum52)
Summation of 5.2: 2.336