In: Computer Science
Initially the value of a is 7.5
Initially x value is 1 and it is increment 0.5 every time upto 10.
(x > a) .* (x-5).^2
Here if x value greater than a then the value is 1(x>a condition true x>a is 1) otherwise 0
x = 1 then (1 > 7.5) .* (1-5).^2 = 0 * (-4)2 = 0 (since 1 not greater than 7.5 so it is 0)
x = 1.5 then (1.5 > 7.5) .* (1.5-5).^2 = 0 * (-3.5)2 = 0
...........................
x = 7.5 then (7.5 > 7.5) .* (7.5-5).^2 = 0 * (2)2 = 0
x = 8 then (8 > 7.5) .* (8-5).^2 = 1 * (3)2 = 9 (since 8 greater than 7.5 so it is 0)
x = 8.5 then (8.5 > 7.5) .* (8.5-5).^2 = 1 * (3.5)2 = 12.25
x = 9 then (9 > 7.5) .* (9-5).^2 = 1 * (4)2 = 16
x = 9.5 then (9.5 > 7.5) .* (9.5-5).^2 = 1 * (4.5)2 = 20.25
x = 10 then (10 > 7.5) .* (10-5).^2 = 1 * (5)2 = 25
Program:
a = 7.5; % Initially the value of a is 7.5
for x = 1:0.5:10 % Loop runs from 1 to 10
fprintf("The value @x=%.2f is %.2f\n",x,(x > a) .* (x-5).^2); %
print x and the result and (x > a) .* (x-5).^2
end
Output: