multiplying

Multiply recursiverly in r

自作多情 提交于 2019-12-12 05:06:43
问题 Having the following matrix and vector. x<-matrix(c(1,4,7, 2,5,8, 3,6,9), nrow = 3) w <- c(1,1,1) res <- c() What is the best way to multiply recursiverly till obtain a desire sum of the results as exemplified: res[1]<-w %*%x[1,] res[2]<-w %*%x[2,] res[3]<-w %*%x[3,] res[4]<-w %*%x[1,] res[5]<-w %*%x[2,] sum(res)>1000 #Multiply recursiverly till the sum of the results sum(res) goes further than 1000. 回答1: Here is how to do it recursively : f <- function(x, w, res){ if (sum(res)>1000) return

Multiplying Elements in a List Containing Pairs

好久不见. 提交于 2019-12-11 22:40:00
问题 I'm trying to write a code (function) using Scheme that: Takes a list of any size as a parameter Multiplies every number of the list together Symbols should be skipped over Values inside pairs should be included in multiplication In other words, results should be as follows: > (mult '(1 2 3)) 6 > (mult '(1 2 x 3 4)) 24 > (mult '(1 2 z (3 y 4))) 24 (mine gives me 2) My code allows me to skip over the symbols and multiply everything. However, once I include a pair inside the list, it acts as

How can I make checkbox data add 25%of the total in my calculation script?

半世苍凉 提交于 2019-12-11 14:54:15
问题 I have a calculator built in Jquery It basically add the data-price="" together, However I need to add 25% onto the the total amount for each check box which is ticked. Right now it just adds the checkbox value to the calculation, I need it to add 25% to the total. So if the current total is £400 and then a checkbox is ticked, the calculator should then take £400 and add 25% to it making it £450 $(function(){ $("select.valuvehiclevalue1").on("change", calc); $("select.valuvehiclevalue2").on(

iOS: GLKit matrix multiplication is broken as far as I can tell

[亡魂溺海] 提交于 2019-12-11 08:18:38
问题 Here's the source code. ANSWER is the correct answer, RESULT is the actual result. Am I blind, or is it calculating a -1 for entry 33 when it should be a 1 ? Here's the code: GLKMatrix4 a = GLKMatrix4Make(-1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000); GLKMatrix4 b = GLKMatrix4Make(1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 0.000000

How to Multiply two Column values and display its Result at the end of each Row?

流过昼夜 提交于 2019-12-08 11:42:20
问题 http://www.koolfree.com/ImageUpload/uploads/1340729929.jpg (Table Image) Hello, I have linked to an Image (because stackoverflow was not allowing me to upload due to less than 10 reputation) in which you can see there is a Table with 9 Columns and 3 Rows and the Table is connected to the Database and all the values in the table are stored in the Database. As you can see there is a Last Column of Total in which I want to display the Multiplication Result of Days and Salary values individually

Recursive multiplication in prolog

自古美人都是妖i 提交于 2019-12-06 09:13:20
问题 New to prolog. edit: using swi-prolog I want to recursively do what the multiplication method already does in prolog without actually using the multiplication method. The algorithm I want to implement it looks something like: multn(N1, N2, output){ if (n2 <=0) return output; else multn(N1, (N2-1), output + N1) } Ex: 4*4 = 4+4+4+4 = 16 edit*: only passing in positive numbers for this algo. my knowledge db looks like: multn(Num1, 0, Result) :- Result is 0. multn(Num1, Num2, Result) :- NewNum2 =

JS multiplying by 100 giving wierd result [duplicate]

大兔子大兔子 提交于 2019-12-05 17:52:54
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 5 years ago . I have: var a = 0.0532; var b = a * 100; b should be returning 5.32 but instead it's returning 5.319999999999999. How do I fix this? JSFiddle here: http://jsfiddle.net/9f2K8/ 回答1: you should use .toFixed() FIDDLE var a = 0.0532; var b = a * 100; b.toFixed(2); //specify number of decimals to be displayed 回答2: This is not an error. Very simply put, javascript is trying to represent 5.32

Find sum of subset with multiplication

人走茶凉 提交于 2019-12-05 01:15:33
问题 Let's say we have got a set {a_1, a_2, a_3, ..., a_n} The goal is to find a sum that we create in the following way: We find all subsets whose length is 3, then multiply each subset's elements (for the subset {b_1, b_2, b_3} the result will be b_1*b_2*b_3 ). At the end we sum up all these products. I am looking for a shortest time-execution algorithm. Example SET: {3, 2, 1, 2} Let S be our sum. S = 3*2*1 + 3*2*2 + 2*1*2 + 3*1*2 = 28 回答1: It is easier to calculate sum of multiplied triplets

imul assembly instruction - one operand?

房东的猫 提交于 2019-12-04 18:44:04
问题 I am using a run-time debugger. EAX: 0000 0023 EDX: 5555 5556 imul edx EAX: aaaa aac2 EDX: 0000 000b I am utterly confused, and can't figure out how this multiply is working. What's happening here? I notice in a similar question here that imul ebx ; result in EDX:EAX I don't understand the EDX:EAX notation though :/ 回答1: When the one-operand form of imul is passed a 32 bit argument (as in your case with EDX ) it effectively means EAX * EDX where both EAX and EDX are 32 bit registers. The

Recursive multiplication in prolog

爷,独闯天下 提交于 2019-12-04 15:47:22
New to prolog. edit: using swi-prolog I want to recursively do what the multiplication method already does in prolog without actually using the multiplication method. The algorithm I want to implement it looks something like: multn(N1, N2, output){ if (n2 <=0) return output; else multn(N1, (N2-1), output + N1) } Ex: 4*4 = 4+4+4+4 = 16 edit*: only passing in positive numbers for this algo. my knowledge db looks like: multn(Num1, 0, Result) :- Result is 0. multn(Num1, Num2, Result) :- NewNum2 = Num2 - 1, multn(Num1, NewNum2, NewResult), Result is Num1 + NewResult. However, when I call: ?- multn