symbolic calculation for series
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
YOGESHWARI PATEL
el 29 de Ag. de 2021
Comentada: YOGESHWARI PATEL
el 31 de Ag. de 2021
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
0 comentarios
Respuesta aceptada
Wan Ji
el 29 de Ag. de 2021
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
Más respuestas (1)
John D'Errico
el 29 de Ag. de 2021
Editada: John D'Errico
el 29 de Ag. de 2021
But you defined U as a double precision array! See the difference.
V = zeros(5)
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')
whos U V
So U is a symbolic array of zeros. Now when you assign elements into U, there is no problem.
U(1) = sym('pi')
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!