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 个评论

Adam
Adam 2019-2-11
编辑:Adam 2019-2-11
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.

请先登录,再进行评论。

 采纳的回答

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 个评论

this is the complex equation ; should I be putting it as it is or in e^power form ? cavity.JPG
Torsten
Torsten 2019-2-12
编辑:Torsten 2019-2-12
omega_half = ...;
delta_omega = ...;
beta = ...;
U_in = ...;
dVdt = @(t,V) -(omega_half-1I*delta_omega)*V + 2*beta/(1+beta)*U_in;
Yup; I tried that. But I get my output like :
equation.JPG
instead of something like this -- Capture.JPG
Just reflect it.
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 )
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.
Perfect got it! Thanks. I wish I could accept ur answer
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
The differential equations and their solutions are completely different. So you can't expect that the solution curves coincide.
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 2019-2-12
编辑:Torsten 2019-2-12
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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by