フィルターのクリア

Solution of equation of difference

2 ビュー (過去 30 日間)
Nick Vasilakis
Nick Vasilakis 2022 年 1 月 26 日
編集済み: Yash Srivastava 2022 年 2 月 2 日
Hello! So I'm trying to solve this equation:
for A>0 and being my main variable
Initial value of y(-1)=3 and for N=30 loops
This is the code I've managed to write:
function res = my_matlab_function(A,N)
%definition of y(-1)=3
y_1=3;
% calculating the first value of y(0)
y(0)=0.5*y_1+(0.5*(A^2))/(y_1);
%calculating the rest
for i=1:N-1
y(i)=0.5*(y(i-1)+((A^2)/y(i-1)));
result = my_matlab_function(A,N);
disp(['A= ' num2str(A) 'Result=' num2str(result)])
end
but MATLAB returns to me the followed error:
Not enough input arguments.
Error in my_matlab_function (line 8)
y(0)=0.5*y_1+(0.5*(A^2))/(y_1);

回答 (1 件)

Yash Srivastava
Yash Srivastava 2022 年 2 月 2 日
編集済み: Yash Srivastava 2022 年 2 月 2 日
Hello Nick,
I am assuming that you are trying to run the script file directly by pressing the ‘Run’ button or executing the file from command window. For a file with function to run properly, you need to pass arguments.
You may refer the below documentation to pass arguments to functions with the help of ‘Run’ button:
You may also refer the below link to pass arguments to functions using command window:
Also, Array indexing starts from 1 in MATLAB. You may adjust your index values accordingly.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by