complex number : real part and imaginary part

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 Comments

What is your question ?
I want to display only the real part of the complex series but it is displaying in this form previously i used same command and it display the real part and imaginary part separtly
imag(mu*t*cos(x)) - imag(mu*sin(x)) + 6*real(mu*t*cos(conj(x))*sin(conj(x))*abs(mu)^4*cos(x)^2*sin(x)) + real(6*mu*t*cos(conj(x))*sin(conj(x))*abs(mu)^4*cos(x)*sin(x)^2*sym(1i)) + real(mu*t*sin(x)) - 3*real(mu*t*cos(conj(x))^2*abs(mu)^4*cos(x)*sin(x)^2) + 20*real(mu^4*t*cos(conj(x))*abs(mu)^2*cos(x)*sin(x)^4) + real(3*mu*t*cos(conj(x))^2*abs(mu)^4*cos(x)^2*sin(x)*sym(1i)) + real(20*mu^4*t*cos(conj(x))*abs(mu)^2*cos(x)^4*sin(x)*sym(1i)) + real(-2*mu*t*cos(conj(x))*sin(conj(x))*abs(mu)^4*cos(x)^3*sym(1i)) + 3*real(mu*t*sin(conj(x))^2*abs(mu)^4*cos(x)*sin(x)^2) + 20*real(mu^4*t*sin(conj(x))*abs(mu)^2*cos(x)^4*sin(x)) + real(-3*mu*t*sin(conj(x))^2*abs(mu)^4*cos(x)^2*sin(x)*sym(1i)) + real(-20*mu^4*t*sin(conj(x))*abs(mu)^2*cos(x)*sin(x)^4*sym(1i)) - 2*real(mu*t*cos(conj(x))*sin(conj(x))*abs(mu)^4*sin(x)^3) + real(mu*t*cos(conj(x))^2*abs(mu)^4*cos(x)^3) + 4*real(mu^4*t*cos(conj(x))*abs(mu)^2*cos(x)^5) + imag(mu*t*cos(conj(x))^2*abs(mu)^4*sin(x)^3) - real(mu*t*sin(conj(x))^2*abs(mu)^4*cos(x)^3) + real(4*mu^4*t*cos(conj(x))*abs(mu)^2*sin(x)^5*sym(1i)) + real(-4*mu^4*t*sin(conj(x))*abs(mu)^2*cos(x)^5*sym(1i)) - imag(mu*t*sin(conj(x))^2*abs(mu)^4*sin(x)^3) + 4*real(mu^4*t*sin(conj(x))*abs(mu)^2*sin(x)^5) - 40*real(mu^4*t*cos(conj(x))*abs(mu)^2*cos(x)^3*sin(x)^2) + real(-40*mu^4*t*cos(conj(x))*abs(mu)^2*cos(x)^2*sin(x)^3*sym(1i)) - 40*real(mu^4*t*sin(conj(x))*abs(mu)^2*cos(x)^2*sin(x)^3) + real(40*mu^4*t*sin(conj(x))*abs(mu)^2*cos(x)^3*sin(x)^2*sym(1i)) + real(mu*cos(x))
Which of your symbolic constants x, mu and t are complex, which are real ?
imag(mu*t*cos(x))
None of mu, t, or x have been declared as being real-valued, so MATLAB cannot predict the imaginary component of mu*t*cos(x)
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 on 3 Dec 2024
Edited: Torsten on 3 Dec 2024
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.

Sign in to comment.

 Accepted Answer

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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!