GithubHelp home page GithubHelp logo

Comments (11)

littleredcomputer avatar littleredcomputer commented on June 8, 2024 1

Hello, and thanks for writing!

There's a thing called browserify which prepares JS modules written in the node style for the browser. The source code that drives my github pages is on github too, so you can take a peek at how I did it here, using gulp to orchestrate the typescript compilation and browserify steps.

Warning: on the frontend, I'm a dabbler not an expert, so you might find a way to put it together that you like better. For example, other ways to do this include requirejs and webpack

from odex-js.

zahachtah avatar zahachtah commented on June 8, 2024

Hi, and thanks for those pointers. I'll see how far I get, I'll let you know :-)

from odex-js.

zahachtah avatar zahachtah commented on June 8, 2024

I am getting slowly somewhere...

to get an array output of the integration, does this seem like a reasonable (efficient) way or can I get it to store an array of outputs directly, e.g. in out.y (now out.y seems to be the last value only)?:

a=[];
s.denseOutput = true;
out=s.solve(f, 0, [1], 1, s.grid(0.2, function(x,y) {
  a.push(y[0]);
}));

from odex-js.

littleredcomputer avatar littleredcomputer commented on June 8, 2024

Odex has a very Fortran style, so there is no dynamic memory allocation in it, and the array storage that it statically allocates is often recycled. Your solution is what I would write.

from odex-js.

zahachtah avatar zahachtah commented on June 8, 2024

I love it, a javascript library with fortran style :-D

from odex-js.

littleredcomputer avatar littleredcomputer commented on June 8, 2024

Heh. Here's the source if you're curious. Initially, I tried to change the style, but that turned into a fight. In the end, I decided that the original style has virtues of its own (discretion is the better part of valor).

For example, if you don't need to store the whole vector of results because you are plotting them as they are generated, you don't have to. So it's a feature :)

from odex-js.

zahachtah avatar zahachtah commented on June 8, 2024

here's why I prefer fortran before javascript:

I use the following:

var f = function(x, y) {
  return y;
};
data=[];
s.denseOutput = true;
out=s.solve(f, 0, [1], 1, s.grid(0.2, function(x,y) {
  data.push(y[0]);
}));

and data becomes a nice array one can pass to a graphing script,

BUT...change only a little:

var f = function(x, y) {
  return 0.1 * y;
};

and data returns only a single value.....and there's no logic why this happens.

Will have to sleep on this :-)

from odex-js.

littleredcomputer avatar littleredcomputer commented on June 8, 2024
var f = function(x, y) {
  return [0.1 * y[0]];
}

y is always an array even when solving a one-dimensional system. The job of f is to return a vector of the same length as y.

from odex-js.

zahachtah avatar zahachtah commented on June 8, 2024

thanks. working now

from odex-js.

bramvandijk88 avatar bramvandijk88 commented on June 8, 2024

I'm trying to use Browserify to make your package available within the browser too, but so far I have failed doing so. Could you maybe give an example as to how you would do this? I've gone all the way with your examples on github, but it really doesn't allow me to do what I want to do:

Load up your module
Load up my own code
Call Solver() from my own code in the browser

Thanks for the help :)

<html>
    <head><title>Some ODE integration </title></head>
    <!--<script type="module" src="./odex.js"></script>-->
            <script type="module" src="some_ode_thing.js"></script>
    <body>
    </body>
</html>

With some_ode_thing.js being:

import {Solver, Derivative} from './odex.js'

var s = new Solver(2);
var eq = function(x, y) {
    return [y[1], -y[0]];
};
// This is y'' = -y, y(0) = 1, y'(0) = 0, e.g. cos(x)
console.log(s.solve(eq, 0, [1, 0], Math.PI));
// We observe that at x = π, y is near -1 and y' is near 0,
// as expected.

As discussed above, this won't work in the browser, although running a nodejs version (with require) works perfectly fine:

user@computer$ node lotka_volterra.js 
{ y: [ -1.0000012130554767, 2.867958371527322e-7 ],
  outcome: 0,
  nStep: 8,
  xEnd: 3.141592653589793,
  nAccept: 8,
  nReject: 0,
  nEval: 114 }

I tried to use browserify, but didn't get really far.

[Resolved]

Alright, I found a way of doing it, i was just browserifying the wrong way. For future troubleshooters: here's what to do with the above code to run it in the browser:

browserify some_ode_thing.js -o out.js

And then run out.js within your html code.

from odex-js.

littleredcomputer avatar littleredcomputer commented on June 8, 2024

from odex-js.

Related Issues (2)

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.