How to? - Complex numbers

dVdotdt= @(-(Whalf-1i.*w).*V + alfa.*Uin);
(Whalf-1i.*w) part is complex.
When I put the above in my equation I get 'Warning: Imaginary parts of complex X and/or Y arguments ignored'
I am not sure if my syntax is correct to be honest as my answer should be exponential but it is a straight line; also does ode handle complex well- maybe thats the reason my curve is flawed.

1 comentario

Adam
Adam el 11 de Feb. de 2019
Editada: Adam el 11 de Feb. de 2019
You defined a function of two inputs, t and y yet you don'y use either of them in the function so it will just be a constant, defined by the variables you do give which, I assume, are in the workspace at the time you create this function handle. I have no idea where t and y are supposed to fit into your equation though.

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 11 de Feb. de 2019

0 votos

E.g., for an anonymous function you need to give the input argument list first. E.g., for a generic derivative function that takes t and y as inputs, the syntax would be this:
dydt = @(t,y) some_expression_involving_t_and_y_goes_here;

11 comentarios

STP
STP el 12 de Feb. de 2019
this is the complex equation ; should I be putting it as it is or in e^power form ? cavity.JPG
Torsten
Torsten el 12 de Feb. de 2019
Editada: Torsten el 12 de Feb. de 2019
omega_half = ...;
delta_omega = ...;
beta = ...;
U_in = ...;
dVdt = @(t,V) -(omega_half-1I*delta_omega)*V + 2*beta/(1+beta)*U_in;
STP
STP el 12 de Feb. de 2019
Yup; I tried that. But I get my output like :
equation.JPG
instead of something like this -- Capture.JPG
madhan ravi
madhan ravi el 12 de Feb. de 2019
Just reflect it.
STP
STP el 12 de Feb. de 2019
It doesn\t work like that. It should come originally like that with a peak value of around 1.67 at 4.2 ; and here its around 5 (if I reflect it )
Torsten
Torsten el 12 de Feb. de 2019
Analytical solution is
V(t)=V0 - b/a ( 1- exp(a*(t-t0)) )
with
a = -(omega_half-1I*delta_omega)
b = 2*beta/(1+beta)*U_in
and V(t0)=V0.
Compare to your solution and check the constants.
STP
STP el 12 de Feb. de 2019
Perfect got it! Thanks. I wish I could accept ur answer
STP
STP el 12 de Feb. de 2019
Editada: STP el 12 de Feb. de 2019
If I am doing it with the analytical solution the curve is a little sharper (the bold curve) whereas with the equation it is flatter ; is it a matlab thing?
Attaching the code for the equation and solution both:
beta=5;
alfa = 2.*beta/(beta+1);
tau1=2.0;
tau2=2.4;
Tc=2.0;
gamma=alfa.*(2-exp(-tau1));
% Time frames
t1=0:0.01:4.2;
t2 = 4.2:0.01:5;
t3 = 5:0.01:8;
dEeA = @(t,y) alfa/Tc * exp(-t/Tc);
tspan = t1;
y0 = 0;
[T1 EeA1] = ode15s(dEeA,tspan,y0);
plot(t1,EeA1)
hold on
figure(1)
dEeB = @(t,y)-gamma *exp(-(t - tau1)/Tc)/Tc ;
tspan = t2;
y0 = EeA1(end);
[T1 EeB1] = ode15s(dEeB,tspan,y0);
plot(t2, EeB1)
Ee2 = EeB1(end);
dEeC = @(t,y) -Ee2*exp(-(t-tau2)/Tc)/Tc;
tspan = t3;
y0 = Ee2;
[T1 EeC1] = ode15s(dEeC,tspan,y0);
plot(t3, EeC1)
hold off
omega_half = 0.090;
delta_omega = 0.16;
beta = 5;
U_in = 0.30;
y1 = 0;
alfa = 2*beta/(1+beta);
t1= [0 4.2]
dV1dt = @(t,V) -(omega_half-1i*delta_omega)*V +alfa*U_in;
[t1 V1] = ode15s(dV1dt, t1, y1)
plot(t1, V1)
hold on
t2 = [4.2 5]
U_in1 = -0.30;
y2= V1(end);
dV2dt = @(t,V) -(omega_half-1i*delta_omega)*V +alfa*U_in1;
[t2, V2] = ode15s(dV2dt, t2, y2)
plot(t2, V2)
hold on
t3 = [5 8]
U_in3 = 0;
y3 = V2(end);
dV3dt = @(t,V) -(omega_half-1i*delta_omega)*V +alfa*U_in3;
[t3, V3] = ode15s(dV2dt, t3, y3)
plot(t3, V3)
comparison.JPG
Torsten
Torsten el 12 de Feb. de 2019
The differential equations and their solutions are completely different. So you can't expect that the solution curves coincide.
STP
STP el 12 de Feb. de 2019
Its the same equation ; only diff being in one i am taking the equation and applying ode solver ; and in the other I have back drafted from solution to find df and then applied ode solver.
Torsten
Torsten el 12 de Feb. de 2019
Editada: Torsten el 12 de Feb. de 2019
No.
The first equation has solution
y(t) = 5/3*(1-exp(-t/2)),
the second equation has solution
y(t)=(0.045/0.0337+0.08/0.0337*i)*(1-exp(-0.09*t)*(cos(0.16*t)+i*sin(0.16*t)))
(both only for the t1-range).
Doesn't look the same to me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

STP
el 11 de Feb. de 2019

Editada:

el 12 de Feb. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by