How to see the algorithm of the defaultm projection - matlab

I'm doing a research about map projections. I use this script:
koordinat = [0 102;...
0 103.5;...
-1 103.5;...
-1 102];
lat = koordinat(:,1);
lon = koordinat(:,2);
mstruct = defaultm('utm');
mstruct.geoid = referenceEllipsoid('wgs84','meters');
mstruct.zone = utmzone(koordinat);
mstruct = defaultm(mstruct);
[x,y] = mfwdtran (mstruct,lat,lon);
format long g
luas = polyarea(x,y)
By using the "defaultm" and "mfwdtran" function, I can calculate the projected coordinate. Buut, my fellow researcher is feeling doubtful about these 2 Matlab functions. Do you know how to see the script of these two functions?
I already opened the defaultm.m and mfwdtran.m, but I didn't see anything like an m-file from mathworks.com called "deg2utm.m".
Any suggestion will helps.
Thank you

Related

Matlab logncdf function is not producing expected result

So on this problem it seems pretty straight forward we are given
mean of x = 10,281 and sigma of x = 4112.4
We are asked to determine P(X<15,000)
Now I thought the code for this in matlab should be super straightforward
mu = 10281
sigma = 4112.4
p = logncdf(15000,10281,4112.4)
However this gives
p = .0063
The given answer is .8790 and just looking at p you can tell it is wrong because we are at 15000 which is over the mean which means it should be above .5. What is the deal with this function?
I saw somewhere you might need to take the exp(15000) for x in the function that results in a probability of 1 which is too high.
Any pointers would be much appreciated
%If X is lognormally distributed with parameters:-
mu = 10281;
sigma = 4112.4;
%then log(X) is normally distributed with following parameters:
mew_actual = log((mu^2)/sqrt(sigma^2+mu^2));
sigma_actual = sqrt(log((sigma^2)/(mu^2) +1));
Now you can use either of the following to compute CDF:-
p = cdf('Normal',log(15000),mew_actual,sigma_actual)
or
p=logncdf(15000,mew_actual,sigma_actual)
which gives 0.8796
(which I believe is the correct answer)
The answer given to you is 0.8790 because if you solve the question by hand, you'll get something like: z = 1.172759 and when you look this value in the table, you can only find z = 1.17(without the rest of decimal places) and for which φ(z)=0.8790.
You can verify the exact answer using this calculator. The related screenshot is attached below:

How to write many functions depending on each other in matlab

I have some functions are depending on each ther , the functions are from this book page 136 http://www.cs.helsinki.fi/u/ahyvarin/papers/bookfinal_ICA.pdf .. I functions are presented below , How to write following functions in matlab ??
y(t) = W(t-1)*x(t)
h(t) = P(t-1)*y(t)
P(t)=(1/B)*Tri[P(t-1)-m(t)*h^T(t)]
m(t) = h(t)/(B+y^T(t))*h(t))
e(t) = x(t)-W^T(t-1)*y(t)
W(t) = W(t-1) + m(t)*e^T(t)
It is solving the weight matrix W(t) iteratively .. I tried to do like this in matlab but I did not work so may be you can advice to correct the code :
for i=1:10
e=randn(3,5000);
A=[1 0 0;-0.5 0.5 0;0.3 0.1 0.1];
x=A*e;
y(t) = W(t-1)*x(t)
h(t) = P(t-1)*y(t)
P(t)=(1/B)*Tri[P(t-1)-m(t)*h^T(t)]
m(t) = h(t)/(B+y^T(t))*h(t))
e(t) = x(t)-W^T(t-1)*y(t)
W(t) = W(t-1) + m(t)*e^T(t)
end
Thanks
Ok. I can't really understand what you want, but your code shows that you don't understand some moments. I will try to clarify some moments to you:
for i = 2:10
x = rand(3);
y = W(:,:,i-1)*x;
h = P(:,:,i-1)*y;
m=h/(1+y'*h);
P(:,:,i)=P(:,:,i-1)*m*h';
e=x-W(:,:,i-1)'*y;
W(:,:,i)=W(:,:,i-1)+m*e';
end
You must go something like this: 1. you calculate x and use it to calculate other functions.
2. all of them are matrices. So you need to define it first. For example y = ones(3) etc. 3.Thats not y^T or e^T. Its transposing. If you do not feel difference it's early for you to solve this task :)
And the last: Tri function will create a some kind of problems to you, but it's defined at 136 page.
P.S. i missed beta becouse of don't know what is it :)

Calculate the length of a trajectory over earth - Matlab

I have a trajectory defined in Lat/Long coordinates in "n" points. I need to estimate its length over the surface of the earth:
Lat = [la1 la2 la3 la4 la5 la6];
Lon = [lo1 lo2 lo3 lo4 lo5 lo6];
How can I do this in Matlab? I've tried to use the command distance, but it seems it doesn't do this?
Thanks!
[arclen,az] = distance(lat1,lon1,lat2,lon2)
[arclen,az] = distance(lat1,lon1,lat2,lon2,ellipsoid)
Check the matlab documentation
Something similar to this shouldn't be very hard to write:
sum = 0;
for i=1:(size(Lat)-1)
sum = sum + distance(Lat(i),Lon(i),Lat(i+1),Lon(i+1));
//end (Sorry I haven't used matlab in over a year, and forgot the syntax)

Need someone to thoroughly explain this code for me (Fourier transform, sampling...)

dear stackoverflow members, i have a matlab homework. and im having trouble understanding how this piece of code:
m = [ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];
was put and what does it do? .
It is supposed to plot this function: http://s22.postimg.org/8e3ieonoh/Untitled.gif
Here's the full code:
t0 = 0.15;
ts = 0.001;
fc = 250;
fs = 1/ts;
df = 0.3;
t = [0:ts:t0];
m = [ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];
Thanks.
This creates the time sequence as a long array. ones(1,t0/(3*ts)) means when t<=t0/3, the function obtain 1; -2*ones(1,t0/(3*ts)) indicates the second value in the original function within the range of [t0/3,t0/3*2]. zeros(1,t0/(3*ts)+1) is the rest part of function. The time interval between two consecutive points in your curve is ts.
To avoid the warning, use
m = [ones(1,floor(t0/(3*ts))),-2*ones(1,floor(t0/(3*ts))),zeros(1,floor(t0/(3*ts))+1)];

Tabulated values's management in MATLAB

I have to build a function from tabulated values (two columns) which are written in a text file. The process to make it is the following:
Use the command importdata to read the data file
Xp = importdata('Xp.dat','\t',1);
Store each column in a variable
x = Xp(1:18304,1);
y = Xp(1:18304,2);
Make a curve fitting with both variables
ft = fittype('linearinterp');
datos.f_Xp = fit(x,y,ft);
However, when I am profiling the code I have found out that my bottleneck are the built-in functions fittype.fittype, fittype.evaluate, cfit.feval, ppval and cfit.subsref
which are related to the curve fitting. So I ask myself how I should manage the tabulated values for improving my code.
you're trying to fit 18304 data points to a curve. Also, you're using linearinterp... which means a routine is being run in a piecewise fashion. if you want to make the code faster use less datapoints.
Or perhaps try:
ft = fittype('poly1');
Not sure is it will be the answer you need as I don't have access to the data
May be "Eval" function could work in your case,
some simple example :
A = '1+4'; eval(A)
ans =
5
P = 'pwd'; eval(P)
ans =
/home/myname
and a bit more advanced!
for n = 1:12
eval(['M',int2str(n),' = magic(n)'])
end
Also, it has a sister name "feval"
guess, what does it do !
[V,D] = feval('eig',A)
[V,D] = eig(A)
and here
function plotf(fun,x)
y = feval(fun,x);
plot(x,y)
You are right ! all are equivalent,
check out here and find more relevant function