Plot an equation (sigma operator)

조회 수: 4 (최근 30일)
Fatemeh Salar
Fatemeh Salar 2022년 7월 2일
댓글: Star Strider 2022년 7월 2일
Hi everyone,
I would like to plot this equation for x=[-2,2] and x=3, I wrote this code but it ain't working. Could you please tell me how can I make it work ? Thanks in advance.
clc
clear
close all
H=0
for x=-2:0.1:2;
n=3;
for k=0:floor(n/2);
H=H+((-1)^k)*factorial(n)*(x^(n-2*k))/(2^k*factorial(k)*factorial(n-2*k));
end
end
x=-2:0.1:2;
plot(x,H,'r')

채택된 답변

Star Strider
Star Strider 2022년 7월 2일
Try soemthing like this —
n=3;
kv=0:floor(n/2);
xv=-2:0.1:2;
H = zeros(size(xv));
Hv = zeros(size(xv));
for k2 = 1:numel(xv)
x = xv(k2);
for k1 = 1:numel(kv)
Hv(k1) = ((-1)^kv(k1))*factorial(n)*(x^(n-2*kv(k1)))/(2^kv(k1)*factorial(kv(k1))*factorial(n-2*kv(k1)));
end
H(k2) = sum(Hv);
end
x=-2:0.1:2;
plot(x,H,'r')
The ‘H’ variable was being saved as a scalar, not a vector.
.

추가 답변 (1개)

Fatemeh Salar
Fatemeh Salar 2022년 7월 2일
Thank you so much =)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by