y=f(x) where x has different values. if x<0 y=sinx^2+ abs(x)-100*x; if 0<x<100, y=e^(x^2/pi); if x>100, y=log10(cos(x)). run the program for x=-3;23;180 in matlab

main.m
x = [-3, 23, 180];

for i = 1:length(x)
    if x(i) < 0
        y(i) = sin(x(i))^2 + abs(x(i)) - 100*x(i);
    elseif x(i) > 0 && x(i) < 100
        y(i) = exp(x(i)^2 / pi);
    else
        y(i) = log10(cos(x(i)));
    end
end

disp(y)
237 chars
14 lines

The program starts by defining an array that contains the values of x to be used. It then uses a for loop to iterate over each value in the array. The program uses conditional statements (if, elseif, else) to determine which mathematical function should be used on the current value of x. Finally, the program prints out the computed values of y using the disp() function.

gistlibby LogSnag