Maxima: equations: eliminate variable inside diff() expression - substitution

I have this code:
(%i3)depends([y,x],t)$
eqsp: [y=2*x,
v=diff(y,t,1)+y];
eliminate(eqsp,[y]);
(eqsp) [y=2*x,v='diff(y,t,1)+y]
(%o3) [-'diff(y,t,1)-2*x+v]
And this is a picture for better visualization:
PNG of code in wxMaxima
I was expecting that Maxima would perform a substitution of "y" in the second equation, and then differentiate to get "[-2*diff(x,t,1)-2*x+v]".
This is of course not the real problem (which has many more equations), it's just that I think I'm missing some concept here for Maxima to do what I want.
Thanks in advance for your comments. I'm a newbie in Stackoverflow and in Maxima, sorry if I made some mistake.

Related

Dynamic hedge ratio in R

I was trying to convert the Chan code about Pairs Trading strategy with dynamic hedge ratio into R.
I have already done all work with a steady hedge, but if I want to replicate his "for" loop I'm in trouble. Here my code for that part
lookback=20
hedge=rep(NaN,length(stockY))
for (i in lookback:length(hedge)){
reg=lm(stockY[i-lookback +1:i]~stockX[i-lookback +1:i])
hedge[i]=reg[1]$coeff[2]
}
I tried many different attempts but my low level in R is pretty evident here. I'm not trying to use a "lapply" function but just a for loop. Hope someone can help me. Thanks
Ok It seems I did it. The following is my code:
lookback=20
hedge=data.frame(hedge=rep(0,length(stockY)))
for (i in lookback:length(stockY)){
reg=summary(lm(stockY[i-lookback +1:i]~stockX[i-lookback +1:i]))
hedge[i,1]=reg$coefficients[2,1]
}
So, now I'd know how to extract my residuals. I mean, I need to list all residuals from regression. Unfortunately if I write reg$residuals it returns my last 20 residuals from the last iteration of the loop. So, I tried to include another "res" vector like "hedge" but.....I can't extract my residuals. Please, can someone help me?

Correlations and what brackets indicate

I have this code, from Julian Farawy's linear models book:
round(cor(seatpos[,-9]),2)
I am unsure what [,-9],2 is doing - could someone please assist?
When you are learning new stuff nested functions can be difficult. This same computation could be accomplished in steps, which might be easier for you to see what KeonV and MrFlick are suggesting.
Here is an alternative way of doing this the same functions but easier steps to differentiate with simple explanations.
sub_seatpos<- seatpos[,-9]
this says take a subset of all rows and all columns EXCEPT column number nine and save it into sub_seatpos (this subseting was done in the initial code, but not saved into a new variable. This just makes seeing how each step works easier).
and reflects the bold portion below
round(cor(seatpos[,-9]),2)
cor_seatpos <- cor(sub_seatpos)
This takes the correlation for sub_seatpos and saves them into a variable named cor_seatpos. It reflects the part listed below in bold
round( cor( seatpos[,-9] ),2)
The final step just says round the correlation to 2 decimal places and would look like this in separate lines of code.
round(cor_seatpos, 2)
it is reflected in the bold below
round( cor(seatpos[,-9]),2)
What makes this confusing is that all of the functions are nested. As you become more proficient, this becomes less of a difficulty to read. But it can be confusing with new functions.

Expressing set of sequences as one sequence

This is a discrete math problem, and i was hoping that someone will guide me in the right direction on how to go about solving it...
I have the following set of sequences:
a_(2n) = 8^n
This will give me the values of all the even terms
a_(2n+1) = (-3)8^n
This will give me the values of all the odd terms
I would like to know if there's a way for me to express the values of all terms (both even and odd) using only one formula! Would you please help me!
Thank you,
You can define it as follows:
a_k=[-1+2*(-1)^k]*8^(floor(k/2))

Every nth column from in matlab to R

I am trying to translate some matlab code to R.
This is the code:
v_i = vfull(:,i:ns:k*ns);
I think this means take every ns_th column from i to k*ns in the matrix v_i, right? If I am wrong, can someone please tell me what it means?
Regardless, how would one implement this in R?
You interpretation of what Matlab is doing is correct. Here is how to do the equivalent in R
v_i = vfull[ ,seq(i,(k*ns),ns)]

Sum up with R base

Sorry, that I didn't wrote the sum function in latex. I tried $$ but that didn't work...
I am a beginner in R and I want to sum up:
Sum from i=0 to n by 1.054^i
I reserached the sum() function in R. However, it seems to me that is only can just add elements and not include an index or something.
So my question is: Can I solve that with a simple sum function or do I have to use a for loop for example?
I really appreciate your answer!
UPDATE
Here is a link to my sum(sorry that I cannot post it, but I need more reputation :(link )
In R most operations are vectorized, it requires changing the mindset a bit from other languages and for this question the answer is rather than looping, you simply do the entire operation on your sequence of numbers "at once":
sum(1.054^(0:n))

Resources