complex number : real part and imaginary part

50 views (last 30 days)
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
yogeshwari patel
yogeshwari patel on 3 Dec 2024 at 10:15
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 at 12:29
Edited: Torsten on 3 Dec 2024 at 12:30
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

Walter Roberson
Walter Roberson on 3 Dec 2024 at 11:00
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!