Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiator block #2143

Open
Tirpitz93 opened this issue Oct 7, 2022 · 2 comments
Open

Differentiator block #2143

Tirpitz93 opened this issue Oct 7, 2022 · 2 comments

Comments

@Tirpitz93
Copy link

Is your improvement request related to a problem? Please describe.

  • I cannot seem to find a differentiator block in the standard lib, yet there is an integrator block.
  • Is there a reason for this, is it named something else?
  • I implimented a simple one for myself but I think this should probably be part of the standard lib.

Describe the solution you'd like

  • A differentiator block in the standard library.
  • A Difference block.

Describe alternatives you've considered

  • I wrote two simple blocks here:
  • I will put a PR against Hopsan/development-libraries

Difference:

        void simulateOneTimestep()
        {
            //Read input variables
            In1 = (*mpIn1);
            Out1 = (*mpOut1);

            //Simulation code


            //Write output variables
            (*mpOut1) = In1 - prev;
            prev = In1;
        }

and Differentiator

        void simulateOneTimestep() override
        {
            //Read input variables
            In1 = (*mpIn1);
            Out1 = (*mpOut1);

            //Simulation code


            //Write output variables
            (*mpOut1) = (In1 - prev)/mTimestep;
            
            prev = In1;
        }

@Tirpitz93
Copy link
Author

PR Here: Hopsan/development-libraries#6

@robbr48
Copy link
Contributor

robbr48 commented Oct 11, 2022

Good idea. I think the reason we only have an integrator is because integration is more commonly used. Also numerical differentiation can be sensitive to noise, but this problem is more significant for variable step-size simulation. In Hopsan it should work I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants