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 个评论
Adam Danz
Adam Danz 2020-4-14
编辑:Adam Danz 2020-4-14
Emre Can Usengul, This is the 3rd time you're asking the same or similar question. The first one was deleted and the second is below. If you need more help, continue the discussion within your question instead of posting the question again.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
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 个评论
Emre Can Usengul
Emre Can Usengul 2020-4-13
So if change the name of folder Tsin.m
Then run
Unrecognized function or variable 'x'.
Ameer Hamza
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 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by