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.

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

 채택된 답변

James Tursa
James Tursa 2019년 2월 11일

0 개 추천

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

STP
STP 2019년 2월 12일
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;
STP
STP 2019년 2월 12일
Yup; I tried that. But I get my output like :
equation.JPG
instead of something like this -- Capture.JPG
madhan ravi
madhan ravi 2019년 2월 12일
Just reflect it.
STP
STP 2019년 2월 12일
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 2019년 2월 12일
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 2019년 2월 12일
Perfect got it! Thanks. I wish I could accept ur answer
STP
STP 2019년 2월 12일
편집: STP 2019년 2월 12일
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 2019년 2월 12일
The differential equations and their solutions are completely different. So you can't expect that the solution curves coincide.
STP
STP 2019년 2월 12일
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에 대해 자세히 알아보기

태그

질문:

STP
2019년 2월 11일

편집:

2019년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by