MATLAB Answers

symbolic calculation for series

조회 수: 2(최근 30일)
YOGESHWARI PATEL
YOGESHWARI PATEL 2021년 8월 29일
댓글: YOGESHWARI PATEL 2021년 8월 31일
syms x t
U=zeros(5)
for k=1:5
if mod(k,2)~=0
U(k,1)=0
else
U(k,1)=(((-1)^(k-2))/factorial(k))*sym(pi);
end
end
I want to to assign U(k,1) value in terms of pi not in numbers

채택된 답변

Wan Ji
Wan Ji 2021년 8월 29일
Hi friend,
Just define U as a symbolic array, it works in my matlab
syms x t
syms U [5,1] % I think what you need is 5-by-1 matrix
for k=1:5
if mod(k,2)~=0
U(k,1)=0;
else
U(k,1)=(((-1)^(k-2))/factorial(k))*pi;
end
end
U
The result is
U =
0
pi/2
0
pi/24
0
  댓글 수: 1
YOGESHWARI PATEL
YOGESHWARI PATEL 2021년 8월 31일
Thnak you

댓글을 달려면 로그인하십시오.

추가 답변(1개)

John D'Errico
John D'Errico 2021년 8월 29일
편집: John D'Errico 2021년 8월 29일
But you defined U as a double precision array! See the difference.
V = zeros(5)
V = 5×5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Note that zeros(5) creates a 5x5 array. If you wanted a vector of length 5, then use zeros(5,1) or zeros(1,5).
But now, had you done it like this:
U = zeros(5,'sym')
U = 
whos U V
Name Size Bytes Class Attributes U 5x5 8 sym V 5x5 200 double
So U is a symbolic array of zeros. Now when you assign elements into U, there is no problem.
U(1) = sym('pi')
U = 
  댓글 수: 1
YOGESHWARI PATEL
YOGESHWARI PATEL 2021년 8월 31일
Thank you

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by