How to write code in MATLAB?
3 views (last 30 days)
Diaa on 19 Feb 2021
Your code in the question is not clear to me, nevertheless, my code below can be edited to fulfil your needs.
x = 1:10; % array of independent variable
result = zeros(size(x)); % create an array of the output values to be edited
for n = x % loop over the x values
% change the conditions below to satisfy your needs
if n <= 2
result(n) = n^2 - n + 1;
elseif n > 8
result(n) = 2*n^2 + n^2 - 1;
result(n) = 0;
% variable "result" now has the corresponding output values
Paresh yeole on 19 Feb 2021
f(x) = x*x - x + 1;
elseif x<=7 && x>2
f(x) = 0;
f(x) = 2*x*x + x*x-1;
The limits are not clear in the question. But you can adjust them in the if else accordingly.