complex number : real part and imaginary part

조회 수: 7 (최근 30일)
yogeshwari patel
yogeshwari patel 2024년 12월 3일
편집: Torsten 2024년 12월 3일
syms x mu
syms t %c
alpha=1
U=zeros(1,1,'sym');
A=zeros(1,1,'sym');
B=zeros(1,1,'sym');
C=zeros(1,1,'sym');
D=zeros(1,1,'sym');
series1(x,t)=sym(zeros(1,1));
%%%%%%%%%%%%%%%%%%%%% initial condition
%mu=1
%U(1)=mu*exp(1i*x)
U(1)=mu*(cos(x)+1i*sin(x))
u=conj(U(1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1
A(1)=0;
B(1)=0;
C(1)=0;
D(1)=0;
for j=1:i
for k=1:j
A(1)=A(1)+U(k)*U(j-k+1)*U(i-j+1);
B(1)=B(1)+U(k)*diff(U(j-k+1),x,1)*conj(U(i-j+1));
C(1)=C(1)+U(k)*U(j-k+1)*diff(U(i-j+1),x,1);
for l=1:k
for m=1:l
D(1)=D(1)+U(m)*U(l-m+1)*U(k-l+1)*conj(U(j-k+1))*conj(U(i-j+1));
end
end
end
end
U(i+1)=gamma(((i-1)*alpha)+1)/gamma((alpha*(i+1-1))+1)*(1i*diff(U(k),x,2)+2i*B(1)*2i*C(1)+i*D(1));
end
for k=1:2
series1(x,t)=simplify(series1(x,t)+U(k)*(power(t,(k-1)*alpha)));
%series2(x,t)=simplify(series2(x,t)+V(k)*(power(t,(k-1)*alpha)));
end
expand(series1);
m=real(expand(series1))
the last line does display real and imaginary part of the series
  댓글 수: 6
yogeshwari patel
yogeshwari patel 2024년 12월 3일
x , t real variable and mu are real constant . U(1)=mu*(cos(x)+1i*sin(x)) is complex function . So how should i use the command
Torsten
Torsten 2024년 12월 3일
편집: Torsten 2024년 12월 3일
Define x, t and mu as "syms real" as done in @Walter Roberson 's answer.
By default, all symbolic variables are assumed to be of type complex.

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

채택된 답변

Walter Roberson
Walter Roberson 2024년 12월 3일
syms x mu real
syms t real %c
alpha=1
alpha = 1
U=zeros(1,1,'sym');
A=zeros(1,1,'sym');
B=zeros(1,1,'sym');
C=zeros(1,1,'sym');
D=zeros(1,1,'sym');
series1(x,t)=sym(zeros(1,1));
%%%%%%%%%%%%%%%%%%%%% initial condition
%mu=1
%U(1)=mu*exp(1i*x)
U(1)=mu*(cos(x)+1i*sin(x))
u=conj(U(1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1
A(1)=0;
B(1)=0;
C(1)=0;
D(1)=0;
for j=1:i
for k=1:j
A(1)=A(1)+U(k)*U(j-k+1)*U(i-j+1);
B(1)=B(1)+U(k)*diff(U(j-k+1),x,1)*conj(U(i-j+1));
C(1)=C(1)+U(k)*U(j-k+1)*diff(U(i-j+1),x,1);
for l=1:k
for m=1:l
D(1)=D(1)+U(m)*U(l-m+1)*U(k-l+1)*conj(U(j-k+1))*conj(U(i-j+1));
end
end
end
end
U(i+1)=gamma(((i-1)*alpha)+1)/gamma((alpha*(i+1-1))+1)*(1i*diff(U(k),x,2)+2i*B(1)*2i*C(1)+i*D(1));
end
for k=1:2
series1(x,t)=simplify(series1(x,t)+U(k)*(power(t,(k-1)*alpha)));
%series2(x,t)=simplify(series2(x,t)+V(k)*(power(t,(k-1)*alpha)));
end
expand(series1);
m=real(expand(series1));
disp(char(m))
mu*cos(x) + mu*t*sin(x) + mu^5*t*cos(x)^5 + 4*mu^6*t*cos(x)^6 + 4*mu^6*t*sin(x)^6 + 2*mu^5*t*cos(x)^3*sin(x)^2 - 20*mu^6*t*cos(x)^2*sin(x)^4 - 20*mu^6*t*cos(x)^4*sin(x)^2 + mu^5*t*cos(x)*sin(x)^4

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by