From: Benjamin on
Hello Simulinkfriends,

i want to simulate a capacitor with the expression Uc = U0*(1-e^(-t/tau)). I use a Embedded Matlab Fcn, the code is:

function y = fcn(u,t)
%#eml
R = 1e3;
C = 47e-9;
tau = R*C;
y = u*(1-exp(-t/tau));

the input t is connected to the clock and represents the Simulation time.
A Pulse Generator create an unit step from 0V to 1V.
He show me no Errors and I can simulate, but the resolution is wrong. Is the syntax y = u*(1-exp(-t/tau)); wrong, or should I use a other simulink-block for these Problem ? Any Ideas ?

Thanks for your help!
From: Steven_Lord on


"Benjamin " <benjamin.mattich(a)fh-bielefeld.de> wrote in message
news:i2p1pc$k37$1(a)fred.mathworks.com...
> Hello Simulinkfriends,
>
> i want to simulate a capacitor with the expression Uc = U0*(1-e^(-t/tau)).
> I use a Embedded Matlab Fcn, the code is:
>
> function y = fcn(u,t)
> %#eml
> R = 1e3;
> C = 47e-9;
> tau = R*C;
> y = u*(1-exp(-t/tau));
>
> the input t is connected to the clock and represents the Simulation time.
> A Pulse Generator create an unit step from 0V to 1V. He show me no Errors
> and I can simulate, but the resolution is wrong. Is the syntax y =
> u*(1-exp(-t/tau)); wrong, or should I use a other simulink-block for these
> Problem ? Any Ideas ?

The value of tau in this situation is 47e-6. That means in your expression
for y you're computing (essentially):

y = u*(1-exp(-20000t))

At t = 0, this results in y = 0. If you increase t ever so slightly, to t =
1e-4, the value of y increases to 0.865*u. Somewhere between t = 1e-3 and t
= 2e-3, the value of y becomes fixed at y = u because -20000*t is so small
that exp(-20000*t) becomes smaller than the distance from 1 to the next
smaller double precision number, so 1-exp(-20000*t) becomes exactly 1 in
double precision.

The only solution I can see to this is to avoid the coefficient of t in the
exponential being such a large (in magnitude) negative number, perhaps by
changing the units of R and/or C.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

 | 
Pages: 1
Prev: USRP2 Blockset
Next: Link between AODV and CSMA/CA