I need to reproduce this Matlab operation:
r = U(:,ii)'*Es
Where:
U is a matrix (of complex) andEs is a vector (of complex)
In the end, what I get is the scalar complex value r
Now, I'm trying to do the same with Eigen libs in C++, I've tryied with this:
complex<double> r = U.col(jj) * Es;
and also
complex<double> r = U.col(jj).transpose() * Es;
but it nothing works. Can anybody help me? How can I reproduce the same result?
Thank you!
#chtz, thank you. I've tested your suggestions, and the operation required to reproduce the matlab is:
U.col(jj).dot(Es)
Related
I'm trying to solve the following integral from 0 to t, where the value of t is not known but is surely less than infinite of the following function:
e^(x*s)*x^(b-1)mlf(-x^b,b,b) dx
where s is again a real valued variable of which the value is unknown and b is the parameter of the Mittag-Leffler function, such that 0<b<1. I have tried with "Ryacas" but whenever I try to define a variable as symbolic, let say for example:
x<- Sym("x")
the function "Sym" is not found thus I cannot even try to integrate the function.
Any suggestions will be really appreciated!
Could someone please help me debug this code? I am almost certain there is nothing wrong but Julia keeps giving me an error. The code is basically implementing the problem statement. I am discretizing,then a function computing the sums to compute Erof, then taking the gradient to compute the gradient step used in gradient descent. The debugger in Julia is a nightmare, please help.
If someone has a clue to what the problem is please let me know.
You can see the error line. It says no method matching colon(::Int64, ::Tuple(Int64)). This means N in for i = 1:N is a tuple but it should not be a tuple. N must be an integer.
N = size(U) in line 3 returns a tuple regardless whether U is a Vector or a Multi-Dimensional Array
With range, you should use an integer. So change your N = size(U) to N = length(U) or add the dimension argument to your size call.
I'm currently trying to translate my existing Python code into Julia, and I need to compute a Cholesky Decomposition of a banded, complex matrix. The correct LAPACK routine is cpbtrf (the one currently called by SciPy), and I'm struggling to get it to work in Julia.
I'm not sure what extra details to give, I'm pretty new to Julia and I'm sure I'm doing something stupid. The LAPACK call returns a 1 in the info variable, indicating that something isn't positive definite, but I know it is (SciPy happily decomposes the same matrix).
BlasInt = Base.LinAlg.BlasInt
chk = Base.LinAlg.chkstride1
function cholesky_banded!(ab::StridedMatrix{Complex128}, uplo::Char, n::Integer, kd::Integer)
chk(ab)
ldab = size(ab,1)
info = Ref{BlasInt}()
ccall((:cpbtrf_,Base.liblapack_name),Void,(Ptr{UInt8},Ptr{BlasInt},Ptr{BlasInt},
Ptr{Complex128},Ptr{BlasInt},Ptr{BlasInt}),&uplo,&n,&kd,ab,&ldab,info)
ab, info[]
end
mat = zeros(Complex128,2,3)
mat[1,1:end] = 2
mat[2,1:end-1] = -1
cholesky_banded!(mat,'L',3,1)
edit: Just to clarify, this is a skeleton example. The code I'm writing deals with matrices of order 10^5 or bigger, and can need penta-, hexa-, hepta-diagonal matrices and so on. I need a banded-specific algorithm.
It's all correct except for the LAPACK subroutine. You are using 128 bit complex numbers so you should use :zpbtrf_ instead of :cpbtrf_.
The problem is that I have a variable arma::mat prob_vec and want something equivalent to rmultinom(1, 1, prob_vec) in R.
I found the rmultinom function provided by RcppArmadillo has a weird argument requirement which is different from that in R! So it won't pass the compilation.
I just wanna know how to draw the desired sample in RcppArmadillo, or equivalently in Armadillo. If I need to get the pointer or convert my prob_vec variable, please tell me how.
Many thanks!
Your friendly neighbourhood co-author of RcppArmadillo here: I can assure you that it does not provide rmultinom, but Rcpp does. In fact, it simply passes through to R itself as a quick grep would have told you:
inline void rmultinom(int n, double* prob, int k, int* rn)
{ return ::rmultinom(n, prob, k, rn); }
So I would suggest your first write a five-line C program against the R API to make sure you know how to have rmultinom do what you want it to do, and then use Rcpp and RcppArmadillo to do the same thing on the data in your vector.
This is a really basic question but this is the first time I've used MATLAB and I'm stuck.
I need to simulate a simple series RC network using 3 different numerical integration techniques. I think I understand how to use the ode solvers, but I have no idea how to enter the differential equation of the system. Do I need to do it via an m-file?
It's just a simple RC circuit in the form:
RC dy(t)/dt + y(t) = u(t)
with zero initial conditions. I have the values for R, C the step length and the simulation time but I don't know how to use MATLAB particularly well.
Any help is much appreciated!
You are going to need a function file that takes t and y as input and gives dy as output. It would be its own file with the following header.
function dy = rigid(t,y)
Save it as rigid.m on the MATLAB path.
From there you would put in your differential equation. You now have a function. Here is a simple one:
function dy = rigid(t,y)
dy = sin(t);
From the command line or a script, you need to drive this function through ODE45
[T,Y] = ode45(#rigid,[0 2*pi],[0]);
This will give you your function (rigid.m) running from time 0 through time 2*pi with an initial y of zero.
Plot this:
plot(T,Y)
More of the MATLAB documentation is here:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ode23tb.html
The Official Matlab Crash Course (PDF warning) has a section on solving ODEs, as well as a lot of other resources I found useful when starting Matlab.