Finding Multiplier Matrix [closed] - math

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am trying to find unknown matrix multiply matrix with knowing matrix
A*c=b
where b is defined vector, A is defined matrix 8x8, c is unknown vector.
I know, I can not divide matrix but what is the solution for this situation ??

This is basically a system of simultaneous linear equations. You can solve it using Gaussian elimination.
As for matrix "division", what you really have in mind is an inverse matrix, i.e. a matrix A-1 such that
AA-1=A-1A=I
where I is the identity matrix. If A is invertible then A*c=b is equivalent to c=A-1b.

The answer by Adam is certainly correct, but you should know that calculating the inverse of the matrix might not be the best solution.
Another to look into is LU decomposition and forward-back substitution. It will be more computationally stable that full Gaussian elimination and calculating the inverse.
You solve the problem in steps like this:
Decompose A = LU; now you'll have LUc = b. L is lower triangular; U is upper triangular.
Let y = Uc; solve Ly = b for y.
Now that you have y, solve for the c vector you want: y = Uc.

Related

How would I specify this function (mathematical formula) in R? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm new to R, and a formula I need to enter includes functions that are beyond the scope of my mathematics experience. In particular, I don't understand what's going on with the subscript to the gamma function. Is this an incomplete gamma function, and if so, is it upper or lower?
Anyhow, the formula is attached in the image. This is the CDF for the 4 parameter Generalized Gamma distribution, taken from a statistical software manual. How would I specify this in R? Any help is much appreciated.
This can be completely wrong, but it seems that function F in the image is a combination of an upper incomplete gamma function and other terms. The subscript seems to be a transformation of x:
y <- ((x - gamma)/beta)^k
If so it could be coded as follows.
f <- function(x, a, beta, gamma, k){
y <- ((x - gamma)/beta)^k
pgamma(y, a, lower = FALSE)*gamma(a)
}
The expression
pgamma(y, a, lower = FALSE)*gamma(a)
is a base R way to code the upper incomplete gamma function. Alternatively, package gsl, function gamma_inc could be used replacing that code line with
gsl::gamma_inc(a, y)

function scale() in R doesn't scale the data symmetrically [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I apologize if my question is simple. I tried to find the answer but I didn't find much info.
I use the scale() function in R to scale my data. What I don't understand is that when I plot my scaled data using matplot() it seems my scaled data aren't symmetric. which means the range of the sacled data is -1,-0.5,0,0.5,1,1.5. As I know, we scale the data to mean zero and standard deviation s. So my data should have a deviation of s from mean but here I have a deviation of 1.5 and a deviation of -1. Why?
Your data are not symmetric around their mean.
Compare the following:
x <- runif(1000) # symmetric around 0.5
y <- rexp(1000) # not symmetric around 1 at all
summary(scale(x))
summary(scale(y))

distribution from percentage with R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have distribution of parameter (natural gas mixture composition) expressed in percents. How to test such data for distribution parameters (it should be gamma, normal or lognormal distribution) and generate random composition based on that parameters in R?
This might be a better question for CrossValidated, but:
it is not generally a good idea to choose from among a range of possible distributions according to goodness of fit. Instead, you should choose according to the qualitative characteristics of your data, something like this:
Frustratingly, this chart doesn't actually have the best choice for your data (composition, continuous, bounded between 0 and 1 [or 0 and 100]), which is a Beta distribution (although there are technical issues if you have values of exactly 0 or 100 in your sample).
In R:
## some arbitrary data
z <- c(2,8,40,45,56,58,70,89)
## fit (beta values must be in (0,1), not (0,100), so divide by 100)
(m <- MASS::fitdistr(z/100,"beta",start=list(shape1=1,shape2=1)))
## sample 1000 new values
z_new <- 100*rbeta(n=1000,shape1=m$estimate["shape1"],
shape2=m$estimate["shape2"])

Approximate the integral using Riemann sum [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to approximate an integral of a function f(x) from -inf to +inf using the Riemann sum.
integrand<-function(x){exp(x)/sum(exp(x))}
integrate(integrand,lower=-Inf,upper=Inf)
Error in integrate(integrand, lower = -Inf, upper = Inf) :
non-finite function value
The solution doesn't exist if that is your true function
You still haven't clarified the function that you want to integrate. Can you write the integral that you want to evaluate, in ordinary mathematical notation, forgetting about R for the moment?
Here's what you've written, and why it doesn't make sense:
x<- seq(-1000,1000, length=1000)
OK, now x is vector of length 1000: (-1000,-997.998,...,997.998,1000)
v <- sum(exp(x))
OK, now v is equal to the sum of exp evaluated for the values on the vector x. And, since exp(1000)=Inf, this means that, from the point of view of R, v is equal to infinity.
f <-(exp(x))/(v)
At this point, you have defined x to be a vector and v to be a scalar, so this expression will set f to be a vector of length 1000. However, since v is infinite, then every value on f is going to be either 0 or NaN.
This all means that
integrate(f, ???? )
is meaningless, because f is not a function.
If you can write, in ordinary mathematical notation, exactly what integral you want to evaluate, someone will probably be able to help you.

How do I calculate amplitude and phase angle of fft() output from real-valued input? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have 24 samples from a real-valued signal. I perform the fft() function on the sample and get the complex output. I want to obtain the amplitude and phase angle of each of the non-redundant harmonics. I know my calculation must account for aliasing since I have real-valued data. How do I:
(1) convert from the two-sided to a one-sided Fourier transform,
I've heard several things here. For example, do I multiply the first 12 harmonics (i.e., 2nd through 13th elements of fft() output) by two and drop the rest of the harmonics (i.e., keep 1st through 13th elements of fft() output)?
(2) calculate the amplitude of the one-sided Fourier transform,
I know I can use the Mod() function, but when do I do this? Before or after I convert from two- to one-sided?
(3) calculate the phase angle of the one-sided Fourier transform.
I know I can use the atan() function on the ratio of imaginary to real parts of the fft() output, but again, when do I do this? Before or after two- to one-sided conversion? Also, what if atan is undefined?
Thanks.
Since your input is real the output of the FFT will be symmetric about N / 2 so you can just look at the first N / 2 bins and scale the magnitude by a factor of 2. For the phase you ideally need an atan2 function which takes the real and imaginary components as separate arguments and returns a 4 quadrant result.

Resources