function file for maclauring series approximation

조회 수: 2 (최근 30일)
melissa tan
melissa tan 2018년 9월 4일
편집: Stephen23 2018년 9월 4일
My function file: function [approx] =cos1(x,n) %Calculates the Malcurin series approximation to cos(x) approx=0; for i=0:n-1 approx=approx+(1)^i*x^(2*i)/factorial(2*i) end
My command window: approx1=cos1(pi/3,1)
approx =
1
approx1 =
1
(How come i generated the value of one term , it comes up two variable with same value? How to minimize it to one variable?)

채택된 답변

Stephen23
Stephen23 2018년 9월 4일
편집: Stephen23 2018년 9월 4일
Without a semi-colon a line of code will print its output:
function [approx] =cos1(x,n)
%Calculates the Malcurin series approximation to cos(x)
approx=0;
for i=0:n-1
approx=approx+(1)^i*x^(2*i)/factorial(2*i);
end ^ you forgot this!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by