i have a function and i need to find the output of the last value. y(n)=1/2*(​y(n-1)+A^2​/y(n-1)) 0<=n<=N-1 (N=30 A=4),When i run it says output arguments not assignet.

1 Ansicht (letzte 30 Tage)
function res = my_matlab_function(A,N)
y(1)=1/2*(3+(A^2/3));
y(2)=1/2*(y(1)+(A^2/y(1)));
for n=2:(N-1)
y(n)=1/2*(y(n-1)+A^2/y(n-1));
end

Antworten (1)

Harry
Harry am 25 Jan. 2022
Bearbeitet: Harry am 25 Jan. 2022
Hi Tasos,
you have not assigned y to res whihc is your function output. I corrected your code in the following way:
function res = my_matlab_function(A,N) % res is te function output
y(1)=1/2*(3+(A^2/3));
y(2)=1/2*(y(1)+(A^2/y(1)));
for n=2:(N-1)
y(n)=1/2*(y(n-1)+A^2/y(n-1));
end
res = y; % Assign it to the res
end
and then you can extract the last value by res(end). I hope it works for you.

Kategorien

Mehr zu Denoising and Compression finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by