how to find a command in MATLAB - matlab

I have a problem:
I use lookfor to find a function or a command in MATLAB, but
Many times lookfor gives some results but when I use help for learning how to use, I see this statament:
No matches found.
What is the problem, If I use the newer version of MATLAB, this problem is solved or not?

This is supposed to happen because these two commands are different!
The lookfor command allows you to search for functions based on a keyword. It searches through the first line of help text, which is known as the H1 line, for each MATLAB function, and returns the H1 lines containing a specified keyword. For example, MATLAB does not have a function named inverse. So the response from
help inverse
is
inverse.m not found.
But
lookfor inverse
finds over a dozen matches. Depending on which toolboxes you have installed, you will find entries like
INVHILB Inverse Hilbert matrix.
ACOSH Inverse hyperbolic cosine.
ERFINV Inverse of the error function.
INV Matrix inverse.
PINV Pseudoinverse.
IFFT Inverse discrete Fourier transform.
IFFT2 Two-dimensional inverse discrete Fourier transform.
ICCEPS Inverse complex cepstrum.
IDCT Inverse discrete cosine transform.
To learn on, check out http://www.thphys.may.ie/CompPhysics/matlab/help/techdoc/basics/getting6.html.

Related

Why i am getting blank graph?How can i solve this issue?

I am trying to plot symbolic variable in MATLAB, for which I have used the same strategy that is available in an answer to a similar question.
This is my code, which outputs a blank graph:
syms t w
x=exp(-t^2)
h=exp(-t)*heaviside(t)+exp(t)*heaviside(-t)
X=fourier(x,w);
H=fourier(h,w);
right=ifourier( rewrite(X*H, 'exp'),t)
fplot(right,[0 8])
How can I make the graph appear?
The problem is that MATLAB ifourier function cannot compute the inverse Fourier transform of the product X*H.
Check that X*H returns:
X*H
Rewriting the expression does not change it at all:
rewrite(X*H, 'exp')
Either way, when computing the inverse Fourier transform:
right=ifourier( X*H,t)
Documentation on the ifourier function states that:
If ifourier cannot transform the input, then it returns an unevaluated
call to fourier.
Since it cannot evaluate explicitly the function, it cannot plot it.

How to implement ifft in matlab?

I have been having a big problem understanding the concept of numerical ifft.
Consider a function in spatial domain like f(x)=-2/pi*Ln(abs(x)) in which x is between -Lx and Lx. The fourier transform of this function is F(w)=2/abs(w).
I want to figure out whether these two are numerically the same using ifft command in Matlab. If you run the simple code below, you will see the difference that bothers me:
clc
clear all
Lx=0.0005;
N=pow2(10);
dx=2*Lx/(N-1);
w=pi/(N*dx)*linspace(-N/2,N/2,N);
Hw=2./abs(w);
hx=1/dx*abs(fftshift(ifft(Hw)));
x=linspace(-Lx,Lx,N);
hxexact=-2/pi.*log(abs(x));
plot(x,hx,x,hxexact,'r')
legend('ifft','exact')
here is the output:
I would appreciate that if anyone could help me with this.
You seem to have some confusion about the FFT for your function, the result you might have been looking for is:
sqrt(2./pi) / w
This is the fft of your function IFF w is positive!
This is the FFT in the general case:
If you use MATLAB's fft function instead of using your own 2./abs(w) you will see that the ifft and the original function align.

how to solve first order of system of PDEs in Matlab

I have a set of 4 PDEs:
du/dt + A(u) * du/dx = Q(u)
where,u is a matrix and contains:
u=[u1;u2;u3;u4]
and A is a 4*4 matrix. Q is 4*1. A and Q are function of u=[u1;u2;u3;u4].
But my questions are:
How can I solve above equation in MATLAB?
If I solved it by PDE functions of Matlab,can I convert it to a
simple function that is not used from ready functions of Matlab?
Is there any way that I calculate A and Q explicitly. I mean that in
every time step, I calculate A and Q from data of previous time step
and put new value in the equation that causes faster run of program?
PDEs require finite differences, finite elements, boundary elements, etc. You can also turn them into ODEs using transforms like Laplace, Fourier, etc. Solve those using ODE functions and then transform back. Neither one is trivial.
Your equation is a non-linear transient diffusion equation. It's a parabolic PDE.
The equation you posted has the additional difficulty of being non-linear, because both the A matrix and Q vector are functions of the independent variable q. You'll have to start by linearizing your equations. Solve for increments in u rather than u itself.
Once you've done that, discretize the du/dx term using finite differences, finite elements, or boundary elements. You should start with a weighted residual integral formulation.
You're almost done: Next to integrate w.r.t. time using the method of your choice.
It's not trivial.
Google found this: maybe it will help you.
http://www.mathworks.com/matlabcentral/fileexchange/3710-nonlinear-diffusion-toolbox

Cross-correlation in matlab without using the inbuilt function?

can someone tell how to do the cross-correlation of two speech signals (each of 40,000 samples) in MATLAB without using the built-in function xcorr and the correlation coefficient?
Thanks in advance.
You can do cross-correlations using fft. The cross-correlation of two vectors is simply the product of their respective Fourier transforms, with one of the transforms conjugated.
Example:
a=rand(5,1);
b=rand(5,1);
corrLength=length(a)+length(b)-1;
c=fftshift(ifft(fft(a,corrLength).*conj(fft(b,corrLength))));
Compare results:
c =
0.3311
0.5992
1.1320
1.5853
1.5848
1.1745
0.8500
0.4727
0.0915
>> xcorr(a,b)
ans =
0.3311
0.5992
1.1320
1.5853
1.5848
1.1745
0.8500
0.4727
0.0915
If there some good reason why you can't use the inbuilt, you can use a convolution instead. Cross-correlation is simply a convolution without the reversing, so to 'undo' the reversing of the correlation integral you can first apply an additional reverse to one of your signals (which will cancel out in the convolution).
Well yoda gave a good answer but I thought I mention this anyway just in case. Coming back to the definition of the discrete cross correlation you can compute it without using (too much) builtin Matlab functions (which should be what Matlab do with xcorr). Of course there is still room for improvment as I did not try to vectorize this:
n=1000;
x1=rand(n,1);
x2=rand(n,1);
xc=zeros(2*n-1,1);
for i=1:2*n-1
if(i>n)
j1=1;
k1=2*n-i;
j2=i-n+1;
k2=n;
else
j1=n-i+1;
k1=n;
j2=1;
k2=i;
end
xc(i)=sum(conj(x1(j1:k1)).*x2(j2:k2));
end
xc=flipud(xc);
Which match the result of the xcorr function.
UPDATE: forgot to mention that in my opinion Matlab is not the appropriate tool for doing real time cross correlation of large data sets, I would rather try it in C or other compiled languages.

How to add white noise process term for a couple of ODEs, assuming the Gaussian distribution?

This question has already confused me several days. While I referred to senior students, they also cannot give a reply.
We have ten ODEs, into which each a noise term should be added. The noise is defined as follows. since I always find that I cannot upload a picture, the formula below maybe not very clear. In order to understand, you can either read my explanation or go the this address: Plos one. You could find the description of the equations directly above the Support Information in this address
The white noise term epislon_i(t) is assumed with Gaussian distribution. epislon_i(t) means that for equation i, and at t timepoint, the value of the noise.
the auto-correlation of noise are given:
(EQ.1)
where delta(t) is the Dirac delta function and the diffusion matrix D is defined by
(EQ.2)
Our problem focuses on how to explain the Dirac delta function in the diffusion matrix. Since the property of Dirac delta function is delta(0) = Inf and delta(t) = 0 if t neq 0, we don't know how to calculate the epislonif we try to sqrt of 2D(x, t)delta(t-t'). So we simply assume that delta(0) = 1 and delta(t) = 0 if t neq 0; But we don't know whether or not this is right. Could you please tell me how to use Delta function of diffusion equation in MATLAB?
This question associates with the stochastic process in MATLAB. So we review different stochastic process to inspire our ideas. In MATLAB, the Wienner process is often defined as a = sqrt(dt) * rand(1, N). N is the number of steps, dt is the length of the steps. Correspondingly, the Brownian motion can be defined as: b = cumsum(a); All of these associate with stochastic process. However, they doesn't related to the white noise process which has a constraints on the matrix of auto-correlation, noted by D.
Then we consider that, we may simply use randn(1, 10) to generate a vector representing the noise. However, since the definition of the noise must satisfy the equation (2), this cannot enable noise term in different equation have the predefined partial correlation (D_ij). Then we try to use mvnrnd to generate a multiple variable normal distribution at each time step. Unfortunately, the function mvnrnd in MATLAB return a matrix. But we need to return a vector of length 10.
We are rather confused, so could you please give me just a light? Thanks so much!
NOTE: I see two hazy questions in here: 1) how to deal with a stochastic term in a DE and 2) how to deal with a delta function in a DE. Both of these are math related questions and http://www.math.stackexchange.com will be a better place for this. If you had a question pertaining to MATLAB, I haven't been able to pin it down, and you should perhaps add code examples to better illustrate your point. That said, I'll answer the two questions briefly, just to put you on the right track.
What you have here are not ODEs, but Stochastic differential equations (SDE). I'm not sure how you're using MATLAB to work with this, but routines like ode45 or ode23 will not be of any help. For SDEs, your usual mathematical tools of separation of variables/method of characteristics etc don't work and you'll need to use Itô calculus and Itô integrals to work with them. The solutions, as you might have guessed, will be stochastic. To learn more about SDEs and working with them, you can consider Stochastic Differential Equations: An Introduction with Applications by Bernt Øksendal and for numerical solutions, Numerical Solution of Stochastic Differential Equations by Peter E. Kloeden and Eckhard Platen.
Coming to the delta function part, you can easily deal with it by taking the Fourier transform of the ODE. Recall that the Fourier transform of a delta function is 1. This greatly simplifies the DE and you can take an inverse transform in the very end to return to the original domain.