How to make this function accept a vector input

1 回表示 (過去 30 日間)
Carlo Speranza
Carlo Speranza 2018 年 11 月 29 日
回答済み: Star Strider 2018 年 11 月 29 日
function y=sineseries(x,n)
sol=0;
for k=1:n
s=(-1).^(k-1)*x.^(2*k-1)./factorial(2*k-1);
sol=sol+s;
end
format long
y=sol
end
How should I modify this function in order to let it accept as input an x vector of 4 elements and give a proper y?

回答 (1 件)

Star Strider
Star Strider 2018 年 11 月 29 日
You function already accepts a vector input for ‘x’.
x = linspace(0, 2*pi, 6);
n = 42;
y = sineseries(x,n)
check = sin(x)
It also returns the same results as the built-in sin function.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by