For my problem I need to iterate numbers 1 to n through the equation 1/(1+25x^2) my current code is
for i = 1:n
result = 1/(1+25*i^2);
end
But this is only outputting one number I want to save the numbers into an array so I can plot them
For my problem I need to iterate numbers 1 to n through the equation 1/(1+25x^2) my current code is
for i = 1:n
result = 1/(1+25*i^2);
end
But this is only outputting one number I want to save the numbers into an array so I can plot them
You can write it as
result = 1./(1+25*(1:n).^2);
or in a for
loop with indexing
result = zeros(1,n);
for j = 1:n
result(j) = 1/(1+25*j^2);
end