How to show a couple of equations in incremental way in xaringan? - r-markdown

Hi I was wondering how to show two equations in incremental way using xaringan in rmarkdown slides like using \pause command in beamer.
ax+by = c (equation 1)
dx+ey = f (equation 2)

Related

Print equation of linear regression model using RMarkdown

I currently have some rather long inline code for producing an equation of just a simple linear regression:
lm(var1 ~ var2 + var3)
But I could have sworn at some point recently I saw some very succinct inline code to produce an equation of that model, but I seem to not have saved it. Any ideas?
(sorry, I found it, using the equatiomatic package)
You don’t need need a package for inline equations. Just put you equation in Rmarkdown between 2 $, example below
$lm(var1 ~ var2 + var3)$
which looks like this rendered in Rmarkdown

Python: Trying to create bar plot from data in multi-index pivot table

I've seen some answers that are tangentially related to my question but they're sufficiently different that I'm still not sure how to go about this. I have a pivot table in Python organized as follows:
and I would like to create a bar plot where on the x-axis I have 6 sections for each of the 6 departments (A,B,C, etc.) and then for each I have two bar plots that show the value in the "Perc Admitted" column for Males and Females, with them colored differently for clarity. I've been trying to use Seaborn's barplot for this, but cannot seem to get it to come together, i.e. trying for example
sns.barplot(data = admit_data, x = 'Dept', y = 'Perc Accepted', hue = 'Gender')
gets me an "ValueError: Could not interpret input 'Dept'" error. Still learning Python and not sure how to best do this...any suggestions would be greatly appreciated. I'm also open to using matplotlib.pyplot or other library if that also provides for an elegant solution. Thank you!

how to get coeefficient bandpass FIR Filter Design with Python

I'm trying to make a DSP with python, I am a beginner, like this site https://mbed.org/cookbook/FIR-Filte
1. I look for coefficients with python, but how to find the coefficient FIR bandpass using hamming window, can you give me an example?
2. how to implement Coefficients to DSP using python in FIR bandpass using a Hamming window (I want to implement DSP with raspberry pi (first option) or on Arduino)
I'm not good in english, i hope you understand what I'm talking about,
thanks
There are several techniques and approaches for designing FIR filters. But if you just want a simple bandpass filter with n_pts points centered at f_c Hz (with sampling rate sr Hz), try:
import numpy as np
import scipy.signal
fir_coeff = np.hanning(n_pts)*np.cos(2.*np.pi*f_c/sr*np.arange(n_pts))
fir_coeff /= np.sum(np.hanning(n_pts))
filtered_signal = scipy.signal.lfilter(fir_coeff, 1.0, signal)
This is a reasonable bandpass filter, with Q about n_pts/(sr/f_c). You increase the Q (make it a narrower bandpass filter) by increasing the filter length n_pts.
Note that if you're trying to implement filters on low-power hardware, you're much better off using IIR filters instead of FIR (if they suit your problem). Thus, a similar filter can be implemented as
# Q = n_pts/(sr/f_c) or defined some other way
w_c = 2*pi*f_c/sr
beta = np.cos(w_c)
BW = w_c / Q
alpha = (1. - np.sin(BW))/np.cos(BW)
G = (1. - alpha)/2.
filtered_signal = scipy.signal.lfilter([G, 0, -G], [1, -beta*(1+alpha), alpha], signal)
For a reasonably narrow filter (n_pts = 33 or something), this should be an order of magnitude faster.
(The expressions are based on slide 14 of http://www.ee.columbia.edu/~dpwe/e4810/lectures/L06-filters.pdf , this is what you learn in a DSP course).

Gauss-Seidel Solver for Python 2.7

Is there a Python 2.7 package that contains a Gauss-Siedel solver for systems with more than 3 linear algebraic equations containing more than 3 unknowns? A simple example of the sort of problem I would like to solve is given below. If there are no templates or packages available, is it possible to solve this in python? If so please could you advise on the best way of going about it. Thanks.
An example of three linear algebraic equations with three unknowns (x,y,z):
x - 3y + z = 10
2x + 5y + z = 4
-x + y - 2z = -13
After a bit of searching around I found the solution was to use the numpy.linalg.solve command. The command uses the LAPACK gesv routine to solve the problem; however I am not sure what iterative technique this uses.
Here is the code to solve the problem if anyone is interested:
a = np.array([[1,-3,1],[2,5,1],[-1,1,-2]])
b = np.array([10,4,-13])
x = np.linalg.solve(a, b)
print x
print np.allclose(np.dot(a, x), b) # To check the solution is found

Implementation of Great Circle Destination formula?

I am writing a Python program to generate some maps in Google Earth, I am using a colleague's script written in Perl and I came to a point where there is this Great Circle call:
#r = great_circle_destination($long, $lat, $bearing, $dist);
What is the equivalent for Python? Is there a module like this:
use Math::Trig ':great_cricle';
I'm pretty sure there's no such thing in the standard library. I'm pretty sure there'd be a python GIS library that have similar functions, but there are many different ways to do this calculation depending on which model of the earth you uses (e.g. spherical earth or ellipsoid earth or something more complex), so you probably would want to check out the source code of the Perl module and translate that to python.
If you want to implement it yourself, you might want to look in this page for a formula for Destination point given distance and bearing from start point: http://www.movable-type.co.uk/scripts/latlong.html
It shouldn't be too difficult to translate that formula to python:
R = ... Radius of earth ...
def great_circle_destination(lon1, lat1, bearing, dist):
lat2 = math.asin( math.sin(lat1)*math.cos(dist/R) +
math.cos(lat1)*math.sin(dist/R)*math.cos(bearing) )
lon2 = lon1 + math.atan2(math.sin(bearing)*math.sin(dist/R)*math.cos(lat1),
math.cos(dist/R)-math.sin(lat1)*math.sin(lat2)
return lon2, lat2