您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Evaluate a polynomial expression at a given value of x using recursion
- // ==UserScript==
- // @name Polynomial Evaluator
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description Evaluate a polynomial expression at a given value of x using recursion
- // @match *://*/*
- // @grant none
- // @license MIT
- // ==/UserScript==
- (function() {
- 'use strict';
- // Function to evaluate a polynomial at a given value of x
- function evaluatePolynomial(coefficients, x, n) {
- // Base case: if n is 0, return the constant term
- if (n === 0) {
- return coefficients[0];
- }
- // Recursive case: compute the polynomial value
- return coefficients[n] * Math.pow(x, n) + evaluatePolynomial(coefficients, x, n - 1);
- }
- // Example coefficients for P(x) = 2x^3 + 3x^2 + 4x + 5
- let coefficients = [5, 4, 3, 2]; // Coefficients are in increasing order of power
- // Value of x at which to evaluate the polynomial
- let x = 2;
- // Degree of the polynomial (highest power)
- let n = coefficients.length - 1;
- // Evaluate the polynomial
- let result = evaluatePolynomial(coefficients, x, n);
- console.log(`The value of the polynomial at x = ${x} is: ${result}`);
- })();