Giter Site home page Giter Site logo

Sin function bug about ahkab HOT 2 CLOSED

ahkab avatar ahkab commented on July 25, 2024
Sin function bug

from ahkab.

Comments (2)

ggventurini avatar ggventurini commented on July 25, 2024

Hello Dan,

Thanks for the nice words. I am very glad you enjoy this library!

Here follows the explanation for that message you see. I agree that it would be arguably good to avoid that condition, so I will patch it away soon.

Verbose answer follows:

The sine function has five parameters:

  • vo, offset voltage in Volt
  • va, amplitude voltage, in Volt
  • freq oscillation frequency in Hertz
  • td time delay, in seconds
  • theta oscillation damping constant in seconds

For all time functions, you may change the parameters at will in your code like, for example:

mysin.td = 1e-6

The change will be effective immediately.

As of now, you can even define a time function with a subset of the parameters and define the missing parameters subsequently, eg after you compute them.

For example, if you leave theta undefined -- I'd venture to guess this is what is happening in your code -- when you try to evaluate the sine, it will complain some parameters are undefined and hence the time function should be impossible to evaluate. Only when it actually comes to evaluate it, the (pretty trivial) algorithm tries to provide a result anyway -- or otherwise it should stop the simulation -- and theta undefined is interpreted as no damping, ie theta == 0 and the damping code is not executed (as damping with null theta means divide by zero) and all is fine.

Providing a default value hard-coded in ahkab would make this error go away. I believe this to be a good idea, especially for theta, which few people use. I will still think a bit about it before patching to make sure this doesn't bite back in unexpected ways.

I will also post here a drawing as time allows.

All the best,

GV

EDIT: clarifications, rewording.

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

It should be fixed in 19eecc2

Now all commonly used parameters are compulsory and all seldom used parameters have a default value.

Noticed I realized I made a mistake whic got fixed too, the old theta corresponds to, according to the usual conventions, 1/theta. I have added the phase lag phi too.

Here is the docstring from devices.sin:

    f(t) = 

        t < td:  
                 vo + va*sin(pi*phi/180)
        t >= td: 
                 vo + va*exp(-(time - td)*theta)*sin(2*pi*freq*(t - td) + pi*phi/180)

    *Parameters:*

    vo: float
        Offset

    va: float
        amplitude

    freq: float
        frequency in Hz

    td: float, optional
        time delay before beginning the sinusoidal time variation, in seconds. 
        Defaults to 0.

    theta: float optional    
        damping factor in 1/s. Defaults to 0 (no damping).

    phi: float, optional
        Phase delay in degrees. Defaults to 0 (no phase delay).

Please feel free to reopen if you spot any problem.

I will likewise fix the other time functions.

from ahkab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.