function

function pointer with Eigen

大城市里の小女人 提交于 2020-06-29 03:37:49
问题 I am pretty competent with Python, but I'm pretty new to C++ and things like pointers. I try to write some codes for solving ODE with the Eigen package for linear algebra (I will need to deal with lots of matrices later, so I plan to start with it). I have the following code for RK4 and they work: #include "../eigen-eigen-b3f3d4950030/Eigen/Dense" using namespace Eigen; VectorXd Func(const VectorXd& a) { // equations for solving simple harmonic oscillator Vector2d ans; ans(0) = a(1); // dy/dt

How to pass strings with newlines from function to array?

一笑奈何 提交于 2020-06-28 05:44:52
问题 Using Bash I am extracting multiple strings from a binary file. Those strings are filenames, so only NUL and slash can not appear. I use a function that outputs those filenames to an array. I know, I can use IFS separator newline to get filenames with spaces. I hope it is possible to separate functions multiline strings with NUL to save in array, so any *nix legal filename can be worked with. If I set IFS to '' or '\0' I get some numbers instead of names. Not sure why, and maybe I have

Why are empty items in my array and how do I get rid of them? [duplicate]

时光怂恿深爱的人放手 提交于 2020-06-27 15:58:06
问题 This question already has answers here : How can I remove a specific item from an array? (96 answers) Closed 2 years ago . I am using Visual Studio Code. I am trying to return an array with only odd numbers using JavaScript. This is the code: function oddCouple(arr) { for (let i = 0; i < arr.length; i++) { if (arr[i] % 2 == 0) { delete arr[i]; } } return arr; } console.log(oddCouple([2, 6, 7, 0, 1, 3, 7, 5])); This is what I am getting. I do not want the empty items, just odd numbers. [ <2

Memory leak by returning allocated strings

≡放荡痞女 提交于 2020-06-27 14:52:36
问题 A suggested solution for returning a variable length string in Fortran was from this question: function itoa(i) result(res) character(:),allocatable :: res integer,intent(in) :: i character(range(i)+2) :: tmp write(tmp,'(i0)') i res = trim(tmp) end function Am I right in my understanding, that the result of this function is never deallocated? So for large numbers and a lot of calls you could run into memory leaks. So what I mean exactly is the case where I don't assign the result of my

Memory leak by returning allocated strings

耗尽温柔 提交于 2020-06-27 14:52:09
问题 A suggested solution for returning a variable length string in Fortran was from this question: function itoa(i) result(res) character(:),allocatable :: res integer,intent(in) :: i character(range(i)+2) :: tmp write(tmp,'(i0)') i res = trim(tmp) end function Am I right in my understanding, that the result of this function is never deallocated? So for large numbers and a lot of calls you could run into memory leaks. So what I mean exactly is the case where I don't assign the result of my

Is there a way to create a VBA function that can take in both arrays and ranges as input?

巧了我就是萌 提交于 2020-06-27 11:04:11
问题 I am trying to create a function that can take in both a range or an array to perform some further calculations. When an array passes, the function worked fine, but when the function is used on range in the worksheet, it gives me the VALUE! error. My code looks like: Function COMRET(data as variant, N as integer) Dim nrows as long If IsArray(data) Then N = UBound(data,1) Else N = data.rows.count End If '... some other calculations here End Function The problem seems to come from the

How to code elementary symmetric polynomials in R

北慕城南 提交于 2020-06-27 08:22:09
问题 I want to program a function in R that compute the elementary symmetric polynomials. For i=0, 1, ..., p, the i-th elementary polynomial is given by How can I code this function in R? I've tried x<-c(1,2,3,4) crossprod(x) # or for (i in 1:length(x)) print(crossprod((combn(x,i)))) but I don't get the desired result, which is supposed to give e0= 1 e1= 10 e2= 35 e3= 50 e4= 24 回答1: Take the product of each combination using combn(x, k, prod) and then sum that: sympoly <- function(k, x) sum(combn

data.table: How do I pass a character vector to a function get data.table to treat its contents as column names?

有些话、适合烂在心里 提交于 2020-06-24 14:18:13
问题 Here is a data.table: library(data.table) DT <- data.table(airquality) This example produces the output I want: DT[, `:=`(New_Ozone= log(Ozone), New_Wind=log(Wind))] How can I write a function log_those_columns such that the following code snippet outputs the same result? old_names <- c("Ozone", "Wind") new_names <- c("New_Ozone", "New_Wind") log_those_columns(DT, old_names, new_names) Note that I need old_names and new_names to be flexible enough to contain any number of columns. (I see from

Is there a way to run two function at the same time in Google Apps Script with one function as an infinite loop?

可紊 提交于 2020-06-23 18:37:12
问题 I have two functions that I want to run at the same time but I can't just let them run separately as one function contains an infinite loop while(true) . And the problem with JavaScript is that if you where to run two functions, it will finish running the function before running the next one; so if I run a function with a while(true) loop, it will never move onto the next function. If you still don't understand, here is my code: function onOpen(){ // Google Apps Script trigger infLoop() //how

How to write a single Octave script with function definitions compatible with Matlab scripts?

喜夏-厌秋 提交于 2020-06-23 03:09:51
问题 If I write this: clc clear close all format long fprintf( 1, 'Starting...\n' ) function results = do_thing() results = 1; end results = do_thing() And run it with Octave , it works correctly: Starting... results = 1 But if I try to run it with Matlab 2017b , it throws this error: Error: File: testfile.m Line: 13 Column: 1 Function definitions in a script must appear at the end of the file. Move all statements after the "do_thing" function definition to before the first local function