Skip to content

Instantly share code, notes, and snippets.

@miho
Last active November 1, 2018 10:22
Show Gist options
  • Save miho/f5997ca52009ede725bfccd389f7f45c to your computer and use it in GitHub Desktop.
Save miho/f5997ca52009ede725bfccd389f7f45c to your computer and use it in GitHub Desktop.
Function Plotter Template for VRL-Studio
package eu.mihosoft.vrl.user;
/**
* Function Plotter
*/
@ComponentInfo(name="FunctionPlotter", category="ODE")
public class FunctionPlotter implements java.io.Serializable {
private static final long serialVersionUID=1L;
public Trajectory run(
@ParamInfo(name="f(t)")
Function1D f,
@ParamInfo(name="t0", options="value=0.0D")
double t0,
@ParamInfo(name="tn", options="value=10.0D")
double tn,
@ParamInfo(name="h", options="value=1e-2D")
double h,
@ParamInfo(name="Label", options="value=\"Function Plotter\"")
String label){
// create new (and empty) trajectory
Trajectory trajectory = new Trajectory(label);
// check if time interval is correctly chosen by user
if(t0 > tn){
throw new IllegalArgumentException("t0 > tn is not allowed.");
// throw new RuntimeException("Error Text");
}
// add first (i.e. start) timepoint to the trajectory
trajectory.add(t0, f.run(t0));
// TODO add your code here
return trajectory;
}
}
package eu.mihosoft.vrl.user;
import eu.mihosoft.vrl.math.*;
@ComponentInfo(name = "User Function", category = "ODE",
description="Evaluates expressions (e.g. u*cos(t))")
@ObjectInfo(name = "User Function")
public class UserFunction implements Serializable {
private static final long serialVersionUID = 1L;
public Function2D getFunction2D(
@ParamInfo(name = "f(t,u) = ",
options = "xVarName=\"t\";yVarName=\"u\"") GroovyFunction2D f) {
return f;
}
public Function1D getFunction1D(
@ParamInfo(name = "f(t) = ",
options = "xVarName=\"t\";") GroovyFunction1D f) {
return f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment