Tell WolframAlpha to show data field? - curve-fitting

I'm trying to find an approximation for a function that's near y = x^(1/5).
Unfortunately, polynomial approximations for functions below degree 1 don't work. These work if I specify the form manually, but are off by about 5% in the ranges I care about:
FindFit[{{1,1},{1.6875,2},{4.234567901,3},{10.71875,4},{25,5},{53.1797839,6},{104.142857,7},{190.10937,8},{327.189300,9},{535.9375,10}},{a*x^(1/5) + b*x^(1/3) + c*x + d*(1/x) + e},{a,b,c,d,e},x]
1.6616*x^(1/5) + 0.570547*x^(1/3) + -0.00136863*x + -1.445*(1/x) + 0.251113
NonlinearModelFit[{{1,1},{1.6875,2},{4.234567901,3},{10.71875,4},{25,5},{53.1797839,6},{104.142857,7},{190.10937,8},{327.189300,9},{535.9375,10}},{a*x^(1/5)+b*x^(1/3)+c*x+d*(1/x)+e},{a,b,c,d,e},x]
0.251113 - 0.00136863 x + 0.570547 x^(1/3) + 1.6616 x^(1/5) - 1.445/x
FindFit example see https://reference.wolfram.com/language/ref/FindFit.html
NonlinearModelFit example see https://reference.wolfram.com/language/ref/NonlinearModelFit.html
The problem is that I need to explore more forms or provide more data, but I'm limited to 200 characters.
How do I tell it to show the data field beneath the prompt so that I can enter the points {{1,1},{1.6875,2},..} separately? For example:
https://www.wolframalpha.com/input?i=polynomial+fit
https://www.wolframalpha.com/input?i=cubic+fit+calculator
I've tried:
FindFit[%,{a*x^(1/5) + b*x^(1/3) + c*x + d*(1/x) + e},{a,b,c,d,e},x]
find fit
<a_whole_bunch_of_other_stuff_over_a_few_days>
But they don't work and I'm tearing my hair out.. this feels like a huge oversight or even a bug. Does anyone know the magic incantation to show the data field for any query? Or to submit the data and reference it in the next query? Similar to these, but allowing me to enter the form of the equation:
https://www.wolframalpha.com/input/?i=curve%20fitting

Related

Editing table - stargazer

I want to reproduce a similar table to the one I am attaching. I found some data frame online and am using them to practice.
I have 2 problems:
I can't get to remove the Dependent variable title and put Donations($) instead. I tried with dep.var.labels() and with column.labels=c() but it does not work.
I want to put the mean of the dependent variable in the bottom part. It seems like there is no Mean of the dep variable statistics code. I tried using keep.stat = c("rsq", "n", "all") but I only get r squared and observations, and not the rest of the statistics (my idea was to put "all" and then use omit.stat () to get rid of the ones that I do not need).
How do I insert these row labels?
Here is the code I used.
How can I fix this?
library(stargazer)
library(htmltools)
library(htmlTable)
## loading data frame
stargazer(attitude, type="text")
## the model
linear.1 <- lm(rating ~ complaints + privileges + learning + raises + critical,
data=attitude)
linear.2 <- lm(rating ~ complaints + privileges + learning, data=attitude)
## create an indicator dependent variable, and run a probit model
attitude$high.rating <- (attitude$rating > 70)
## table
star.out=stargazer(linear.1, linear.2,
align=TRUE,
covariate.labels=c("Handling of Complaints","No Special Privileges",
"Opportunity to Learn","Performance-Based Raises","Too Critical","Advancement"),
keep.stat = c("rsq","n"), no.space=TRUE, type="html")
Here is the table I want to replicate:

Writting many Equations for NDSolve

I'm trying to write the master equations for genetic networks, as they are many equations I'm trying to make a table for writing all of them at time. However, I don't know how to adjust the boundaries, I mean:
I wrote a matrix with all the variables that I need:
p={{p11,p12},{p21,p22}}
Then I wrote a table for creating the differential equations:
Table[p[[i,j]]'[t]== p[[i-1,j]][t]+p[[i,j-1]][t]+p[[i+1,j]][t]+p[[i,j+1]][t],{i,1,2},{j,1,2}]
However the part p[[i-1,j]] when i=1 is p[[0,1]]but it doesn't exist and I need to put 0 instead of this but I dont not how. I tried with If but it doesn't work well. What can i do?
Will this work for you?
pf[i_,j_]:=If[i<1||i>2||j<1||j>2,0,p[[i,j]][t]];
Table[p[i,j]'[t]== pf[i-1,j]+pf[i,j-1]+pf[i+1,j]+pf[i,j+1],{i,1,2},{j,1,2}]
which returns
{{p[1, 1]]'[t] == p[[1,2]][t] + p[[2,1]][t], p[1, 2]]'[t] == p[[1,1]][t] + p[[2,2]][t]},
{p[2, 1]]'[t] == p[[1,1]][t] + p[[2,2]][t], p[2, 2]]'[t] == p[[1,2]][t] + p[[2,1]][t]}}

MDX - StrToMember in Range

I'm quite newbie using MDX, I use it in Power BI in order to create different reports.
I'm actually stuck with an issue after a lot of research in different pages, related to Time Ranges.
In the Cube there is a dimension [Time].[Date].[Date], that goes from 2014 to 2020, so I figure out after many hours that all the options using Current Member wouldn't work.
I need to capture a Measure in the last 7, 30, 60, 90 days.
I found two options:
OPTION 1. Using WITH and Member:
`WITH MEMBER [Measures].x AS SUM
({[Time].[Date].&[20190216]:[Time].[Date].&[20190222])
},[Measures].[Avg Loaned])
SELECT NON EMPTY {[Measures].x} on 0
,NON EMPTY ([Time].[Date].[Date]) on 1
FROM [MYCUBE]
WHERE (Some Conditions...)`
OPTION 2. Using WITH, Range and Member
`WITH
SET [Range] AS
{[Time].[Date].&[20190216]:[Time].[Date].&[20190222]}
MEMBER [Measures].x AS SUM
({nonempty([Range]*[Measures].[Avg Loaned])})
SELECT NON EMPTY {[Measures].x} on 0
,NON EMPTY ([Time].[Date].[Date]) on 1
FROM [MYCUBE]
WHERE (Some Conditions...)`
In both cases I get the correct results, and it seems to keep working if I replace
**[Time].[Date].&[20190222]** --> StrToMember("[Time].[Date].&[" + Format(Now(), "YYYYMMDD") + "]")
But it doesn't work when I replace the first date
**[Time].[Date].&[20190216]** --> StrToMember('[Time].[Date].&[' + Format(dateadd('d',-7,Now()), 'YYYYMMDD') + "]")
OR
**[Time].[Date].&[20190216]** --> StrToMember('[Time].[Date].&[' + Format(dateadd('d',-7,cdate(Now())), 'YYYYMMDD') + "]")
OR
**[Time].[Date].&[20190216]** --> StrToMember('[Time].[Date].&[' + Format(cstr(dateadd('d',-7,Now())), 'YYYYMMDD') + "]")
I'm not sure what's the best way to accomplish the task, OPTION 1 or 2, but the main roadblock is how I'm writting down the starting limit for the range trying to use dateadd.
Thanks in advance, I know that there are many posts about this, I tried to adapt the examples to my code but I failed and after some days I'm not sure what could be the issue.
Rgds
Pablo
In your working example you have StrToMember(" and in non-working example you have StrToMember(', so probably you should use double quotes and not single quotes: StrToMember("[Time].[Date].&["...

In a series of IF - ELSE IF statements, only the first IF works

I am trying to create a New variable "X", from Variables "A" "B" and "C".
This is the code that I am using.
I only get the first option "VAS_USAGE=1", the other options are lost.
What I wanted was for VAS_USAGE to have 1 to 6 values.
What am I doing wrong?
```
compute VAS_USAGE=0.
DO IF ((VAS1=1) AND (VAS2=1) AND (VAS3=1)).
COMPUTE VAS_USAGE=1.
ELSE IF ((VAS1=1) AND (VAS2=1) AND (VAS3=0)).
COMPUTE VAS_USAGE=2.
ELSE IF ((VAS1=1) AND (VAS2=0) AND (VAS3=1)).
COMPUTE VAS_USAGE=3.
ELSE IF ((VAS1=1) AND (VAS2=0) AND (VAS3=0)).
COMPUTE VAS_USAGE=4.
ELSE IF ((VAS1=0) AND (VAS2=0) AND (VAS3=1)).
COMPUTE VAS_USAGE=5.
ELSE IF ((VAS1=0) AND (VAS2=0) AND (VAS3=0)).
COMPUTE VAS_USAGE=6.
END IF.
EXECUTE.```
This is how the nested table looks like. This is what I was expecting to get.
This is what I got.
1.00 = 63
As suggested by #user45392 I would check if the answers 'yes' and 'no' are indeed coded as 1 and 0.
In any case I would suggest avoiding the complex 'do if' scheme which might be prone to errors and harder to debug. For example, you could create VAS_USAGE like this:
compute VAS_USAGE = 100*VAS1 + 10*VAS2 + VAS3.
Or if you want to stick to the specific values you gave in your post, add this:
recode VAS_USAGE (111=1)(110=2)(101=3)(100=4)(1=5)(0=6).
Also if you just want a simple index from 1 to 8 you can do this:
compute VAS_USAGE = 4*VAS1 + 2*VAS2 + VAS3 + 1.

AS3 dynamic text algorithm

Afternoon,
I have an odd algorithm. I would like to populate a string of code dynamically based on some user entry.
I have a multi-dimensional array with data in it and a multi-line input text field.
What I want is for a user to be able to enter some text
example:
00
01 - 02 - 03
comments: 12
my code would identify the numbers an treat everything else as text.
Thus, if my array is data[x][#], the # will correspond to their entry.
I would get
algorithm_string = data[x][0] + "\n" + data[x][1] + " - " + data[x][2] + " - " + data[x][3] + "\n" + "comments: " + data[x][12]
So the algorithm would construct the above, and then I could run through the code.
for(var x:int = 0; x < data.length; x++){
some_object._display_text.text = algorithm_string;
}
Ok so I want to first say that relying on a user to put in the entry exactly the way you want is probably not a good idea. They WILL make mistakes and your code WILL eventually not work as expected. I would recommend using 5 inputs restricted to numeric input, and labeling each field with which number should go in it.
However, you can accomplish what you are trying to do above like this:
var parts:Array = myInput.text.split(" ");
for (var i:int=0; i<parts.length, i++){
if(!isNaN(parseInt(parts[i]))){
// you have a number here.
data[x].push(parts[i]);
} else {
//this was not a number so ignore it
}
}
Again let me state I think you should refactor how you get the numbers, but that code will grab the numbers out and put them in the 0,1,2,3,and 4 indexes of your data[x], but relies on the user perfectly inputting the text every time.
Good luck! (refactor) :)

Resources