numerical-methods
Version:
A library that I made while studying Computer Science at UFPB. Documentation's available through TypeScript.
95 lines (93 loc) • 3.07 kB
text/typescript
declare namespace FunctionZeros {
interface Options {
/** Stop iterating as soon as any of the conditions are true. */
bail?: boolean;
/** Which conditions you want to consider when iterating. */
conditionsWhitelist?: [boolean, boolean];
/** Maximum number of iterations. */
maxIterations?: number;
/** For instances where you're iterating over a different function, but still want the results from the original one e.g. iterating over a differentiated function to find a maximum value from the original. */
origFunc?: string;
/** Outputs the relative error between the new X and the last X or the true X, if given. */
relativeError?: number | boolean;
}
interface Params {
func: string;
interval: [number, number];
precision: number;
options?: Options;
}
interface Result {
interval: [string, string];
iterations: number;
}
interface Details {
iteration: number;
x: number;
y?: number;
relativeError?: number;
condition1: number;
condition2: number;
interval: number[];
results: number[];
}
interface Return {
result: Result;
details: Details[];
}
type NewtonRaphson = (info: NewtonRaphson.Params) => NewtonRaphson.Return;
namespace NewtonRaphson {
type Params = Omit<FunctionZeros.Params, "interval"> & {
initialX: number;
};
interface Return {
result: Omit<FunctionZeros.Result, "interval"> & {
x: string;
};
details: Array<Omit<FunctionZeros.Details, "interval" | "results"> & {
prevX: number;
prevY: number;
diffY: number;
}>;
}
}
type Secant = (info: Secant.Params) => Secant.Return;
namespace Secant {
type Params = FunctionZeros.Params;
type Return = FunctionZeros.Return;
}
type Simple = (info: Simple.Params) => Simple.Return;
namespace Simple {
type Params = FunctionZeros.Params;
type Return = FunctionZeros.Return;
}
}
declare const zerosFunctionParams: {
func: string;
interval: string;
precision: string;
options: {
bail: string;
conditionsWhitelist: string;
maxIterations: string;
origFunc: string;
relativeError: string;
};
};
declare const bisection: FunctionZeros.Simple;
declare const falsePosition: FunctionZeros.Simple;
declare const newtonRaphsonParams: {
func: string;
initialX: string;
precision: string;
options: {
bail: string;
conditionsWhitelist: string;
maxIterations: string;
origFunc: string;
relativeError: string;
};
};
declare const newtonRaphson: FunctionZeros.NewtonRaphson;
declare const secant: FunctionZeros.Secant;
export { FunctionZeros, bisection, falsePosition, newtonRaphson, newtonRaphsonParams, secant, zerosFunctionParams };