필터 지우기
필터 지우기

How to write a for loop for summation?

조회 수: 2 (최근 30일)
jake stan
jake stan 2018년 2월 6일
답변: Walter Roberson 2018년 2월 6일
Is there another way to do summation without for loop, or how would I do it with a for loop?
I want to iterate from N = 1 to N = 25 with 0 < x < 2*pi of the equation n*(sin^2(x)+cos^2(x)) I'm not so sure how to do a for loop for the summation

채택된 답변

Birdman
Birdman 2018년 2월 6일
Do not use for loop. If you Symbolic Toolbox, you may use symsum:
syms x n
fun(x)=symsum(n*(sin(x)^2+cos(x)^2),n,1,25)

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 6일
Use sum().
sin(x)^2 + cos(x)^2 = 1, even for complex numbers, so n*(sin(x)^2 + cos(x)^2) is going to simplify to n.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by