How can ask user to enter values of x and n?
3 ビュー (過去 30 日間)
古いコメントを表示
function y = Tsin(x,n)
%Tsin calculates the sin using Taylor formula.
%Input arguments.
%x the angle in degrees, n number of terms.
z=x*pi/180;
y=0;
for k=0:n-1
y=y+(-1)^k*z^(2*k+1)/factorial(2*k+1);
end
How can I ask user to enter values of x and n?
If ı use input function, where ı will use this function?
Thank you..
1 件のコメント
採用された回答
Ameer Hamza
2020 年 4 月 13 日
編集済み: Ameer Hamza
2020 年 4 月 13 日
See input() function.
x = input('Input value of x :');
n = input('Input number of series terms (n) :');
y = Tsin(x,n)
4 件のコメント
Ameer Hamza
2020 年 4 月 14 日
Emre, You first need to create the function in a file like this.
Tsin.m:
function y = Tsin(x,n)
%Tsin calculates the sin using Taylor formula.
%Input arguments.
%x the angle in degrees, n number of terms.
z=x*pi/180;
y=0;
for k=0:n-1
y=y+(-1)^k*z^(2*k+1)/factorial(2*k+1);
end
end
save this file and close it.
Now run the following lines in command window
x = input('Input value of x :');
n = input('Input number of series terms (n) :');
y = Tsin(x,n)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!