evaluation

Evaluating a polynomial with Horner's Algorithm and calculating steps (Java)

三世轮回 提交于 2019-12-24 05:52:09
问题 I need help on my java code. What I'm trying to accomplish is to calculate the size of each step on a polynomial: double s = (b-a)/nsteps; The inputs for the polynomial to be created is degree, coefficient, start value of x , stopping value of x , and the number of steps. Whenever I try to run a test, my output is 0 for x and y and I'm not sure what I am missing on my code. Here is my run test on how its supposed to work, but my result for x and y is 0 : Enter degree:2 Enter coefficient 2:1

Evaluating a polynomial with Horner's Algorithm and calculating steps (Java)

不打扰是莪最后的温柔 提交于 2019-12-24 05:52:07
问题 I need help on my java code. What I'm trying to accomplish is to calculate the size of each step on a polynomial: double s = (b-a)/nsteps; The inputs for the polynomial to be created is degree, coefficient, start value of x , stopping value of x , and the number of steps. Whenever I try to run a test, my output is 0 for x and y and I'm not sure what I am missing on my code. Here is my run test on how its supposed to work, but my result for x and y is 0 : Enter degree:2 Enter coefficient 2:1

Prolog Tree Traversal

人盡茶涼 提交于 2019-12-24 05:05:47
问题 Good Day, I am trying to write a Prolog program that given a tree with a functor of a: start(a(f,2,9), X). I want it to square any values inside so that it yields: X = a(f,4,81). I have code that squares numbers in a list already that works. Here's what I have so far: start([],[]). start(Tree, []) :- Tree =.. [P|C], write(P), nl, write(C), nl, squareMe([P|C], []). squareMe([X|T], [Y|Result]) :- % I think the problem is here atom(X), Y=X, squareMe(T, Result). squareMe([X|T], [Y|Result]) :-

Prolog Tree Traversal

微笑、不失礼 提交于 2019-12-24 05:05:11
问题 Good Day, I am trying to write a Prolog program that given a tree with a functor of a: start(a(f,2,9), X). I want it to square any values inside so that it yields: X = a(f,4,81). I have code that squares numbers in a list already that works. Here's what I have so far: start([],[]). start(Tree, []) :- Tree =.. [P|C], write(P), nl, write(C), nl, squareMe([P|C], []). squareMe([X|T], [Y|Result]) :- % I think the problem is here atom(X), Y=X, squareMe(T, Result). squareMe([X|T], [Y|Result]) :-

Order of Function arguments in C++

自闭症网瘾萝莉.ら 提交于 2019-12-24 01:52:53
问题 I was reading " Bjarne Stroustrup's C++ Style and Technique " FAQ where he mentioned about this FAQ What's the value of i++ + i++? In this he has mentioned "...the order of evaluation of function arguments are undefined." when he is refering to f(v[i],i++); example. I am aware of that the order of evaluation of function arguments is unspecified not undefined but in this case is it undefined because we are relying on value of i so as to which v[i] to pass or its an error in the FAQ itself? 回答1

How evaluate concatenated string as indexed XPath expression in VB6

妖精的绣舞 提交于 2019-12-24 00:48:45
问题 I've built an Xpath expression by concatenating strings in VB6: strXPath = "xDOC.selectNodes(" & """/GroupType1""" & ").item(" & CStr(i) & ").selectNodes(" & """/OperationStageCollection/OperationStage""" & ").length" "i" is an integer used to index into I want to evaluate strXPath to get a loop counter, for example: n = CInt(strXPath) n is declared as Integer; strXPath is declared as string. VB6 throws a Type Mismatch error on the above evaluation expression. I must be missing something

R: How to go from a vector of strings to a vector of quotes / names?

*爱你&永不变心* 提交于 2019-12-23 21:16:54
问题 How to get from input = c("a", "b", "c") to output = c(quote(a), quote(b), quote(c)) automatically? 回答1: List apply as.symbol() to your input vector. lapply(X = input, as.symbol) 来源: https://stackoverflow.com/questions/50710103/r-how-to-go-from-a-vector-of-strings-to-a-vector-of-quotes-names

Non standard evaluation in Hadley's advanced R book

时光毁灭记忆、已成空白 提交于 2019-12-23 07:47:08
问题 In Hadley's Advanced R book, there is a piece of code that I cannot understand the output. f <- function(x) substitute(x) g <- function(x) deparse(f(x)) g(1:10) g(x) g(x + y ^ 2 / z + exp(a * sin(b))) Why do they all return "x" ? Especially when g <- function(x) deparse(substitute(x)) returns the "1:10" , "x" , and "x + y ^ 2 / z + exp(a * sin(b))" as expected. 回答1: First, some background information: A promise is an unevaluated argument. A promises comprises of two parts: 1) the code /

IronRuby performance issue while using Variables

瘦欲@ 提交于 2019-12-23 04:09:19
问题 Here is code of very simple expression evaluator using IronRuby public class BasicRubyExpressionEvaluator { ScriptEngine engine; ScriptScope scope; public Exception LastException { get; set; } private static readonly Dictionary<string, ScriptSource> parserCache = new Dictionary<string, ScriptSource>(); public BasicRubyExpressionEvaluator() { engine = Ruby.CreateEngine(); scope = engine.CreateScope(); } public object Evaluate(string expression, DataRow context) { ScriptSource source;

Pretty good heuristic evaluation rules for big TicTacToe 5x5 board

懵懂的女人 提交于 2019-12-22 17:05:33
问题 I have created TicTacToe game. I use minmax algorithm. When the board is 3x3 I just calculate every possible move for a game till the end and -1 for loss, 0 for tie, 1 for win. When it comes to 5x5 it can't be done(to many options(like 24^24) so I have created evaluation method which gives: 10^0 for one CIRCLE inline, 10^1 for 2 CIRCLE inline, ..., 10^4 for 5 CIRCLES inline, but it is useless. Does anybody have better idea for assesment? Example: O|X|X| | | ---------- |O| | | | ---------- X|O