<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body style="font-family:Arial;font-size:14px">
<p>Hello,<br>
<br>
You just have to replace "x" by "wavelength" and "y" by "ln_power". The slopes are the first two component of the optimal vector "popt" :</p>
<pre style="font-family: Monospaced;">
<span style="color: rgb(50, 185, 185);">clear</span>
<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">clf</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(74, 85, 219);">)</span>
<span style="color: rgb(100, 174, 100); font-style: italic;">// Read data - wavelength (in km)), power, 1 standard deviation</span>
<span style="color: rgb(100, 174, 100); font-style: italic;">// Unknown data length; 3 columns -default space delimited</span>
<span style="color: rgb(100, 174, 100); font-style: italic;">// PSD_wavelength.dat from GMT grdfft radially averaged power spectra</span>
data <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(50, 185, 185);">read</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">PSD_wavelength.dat</span><span style="color: rgb(188, 143, 143);">'</span>,<span style="color: rgb(92, 92, 92);">-</span><span style="color: rgb(188, 143, 143);">1</span>,<span style="color: rgb(188, 143, 143);">3</span><span style="color: rgb(74, 85, 219);">)</span>;
wavelength <span style="color: rgb(92, 92, 92);">=</span> data<span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(255, 170, 0);">:</span>,<span style="color: rgb(188, 143, 143);">1</span><span style="color: rgb(74, 85, 219);">)</span>;
power <span style="color: rgb(92, 92, 92);">=</span> data<span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(255, 170, 0);">:</span>,<span style="color: rgb(188, 143, 143);">2</span><span style="color: rgb(74, 85, 219);">)</span>;
std_dev1 <span style="color: rgb(92, 92, 92);">=</span> data<span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(255, 170, 0);">:</span>,<span style="color: rgb(188, 143, 143);">3</span><span style="color: rgb(74, 85, 219);">)</span>;
ln_power <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(50, 185, 185);">log</span><span style="color: rgb(74, 85, 219);">(</span>power<span style="color: rgb(74, 85, 219);">)</span>;
wavenumber <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(188, 143, 143);">1.</span><span style="color: rgb(92, 92, 92);">/</span>wavelength;
f<span style="color: rgb(92, 92, 92);">=</span><span style="color: rgb(174, 92, 176); text-decoration-line: underline;">gcf</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(74, 85, 219);">)</span>;
<span style="color: rgb(100, 174, 100); font-style: italic;">//plot(wavenumber, ln_power)</span>
<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">scatter</span><span style="color: rgb(74, 85, 219);">(</span>wavenumber, ln_power,<span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">marker</span><span style="color: rgb(188, 143, 143);">'</span>,<span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">.</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(74, 85, 219);">)</span>
a<span style="color: rgb(92, 92, 92);">=</span><span style="color: rgb(174, 92, 176); text-decoration-line: underline;">gce</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(92, 92, 92);">.</span><span style="color: rgb(170, 170, 170);">children</span>;
a<span style="color: rgb(92, 92, 92);">.</span><span style="color: rgb(170, 170, 170);">mark_mode</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(188, 143, 143);">"</span><span style="color: rgb(188, 143, 143);">on</span><span style="color: rgb(188, 143, 143);">"</span>
a<span style="color: rgb(92, 92, 92);">.</span><span style="color: rgb(170, 170, 170);">mark_style</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(188, 143, 143);">0</span>
a<span style="color: rgb(92, 92, 92);">.</span><span style="color: rgb(170, 170, 170);">mark_size_unit</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(188, 143, 143);">"</span><span style="color: rgb(188, 143, 143);">point</span><span style="color: rgb(188, 143, 143);">"</span>
a<span style="color: rgb(92, 92, 92);">.</span><span style="color: rgb(170, 170, 170);">mark_size</span><span style="color: rgb(92, 92, 92);">=</span><span style="color: rgb(188, 143, 143);">3</span>
<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">xlabel</span> <span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">wavenumber k (km-1)</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(74, 85, 219);">)</span>
<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">ylabel</span> <span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">Log (Power)</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(74, 85, 219);">)</span>
<span style="color: rgb(176, 24, 19);">function</span> <span style="color: rgb(131, 67, 16); font-weight: bold;">y</span><span style="color: rgb(92, 92, 92);">=</span><span style="text-decoration-line: underline;">fun</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">x</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">param</span><span style="color: rgb(74, 85, 219);">)</span>
a <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(131, 67, 16); font-weight: bold;">param</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">1</span><span style="color: rgb(74, 85, 219);">)</span>;
b <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(131, 67, 16); font-weight: bold;">param</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">2</span><span style="color: rgb(74, 85, 219);">)</span>;
theta <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(131, 67, 16); font-weight: bold;">param</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">3</span><span style="color: rgb(74, 85, 219);">)</span>;
phi <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(131, 67, 16); font-weight: bold;">param</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">4</span><span style="color: rgb(74, 85, 219);">)</span>;
c <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">x</span><span style="color: rgb(92, 92, 92);"><</span>theta<span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(92, 92, 92);">*</span>a<span style="color: rgb(92, 92, 92);">+</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">x</span><span style="color: rgb(92, 92, 92);">>=</span>theta<span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(92, 92, 92);">*</span>b;
<span style="color: rgb(131, 67, 16); font-weight: bold;">y</span> <span style="color: rgb(92, 92, 92);">=</span> c<span style="color: rgb(92, 92, 92);">.*</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">x</span><span style="color: rgb(92, 92, 92);">-</span>theta<span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(92, 92, 92);">+</span>phi;
<span style="color: rgb(176, 24, 19);">endfunction</span>
<span style="color: rgb(176, 24, 19);">function</span> <span style="color: rgb(131, 67, 16); font-weight: bold;">r</span><span style="color: rgb(92, 92, 92);">=</span><span style="text-decoration-line: underline;">residual</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">param</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">x</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">y</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">f</span><span style="color: rgb(74, 85, 219);">)</span>
<span style="color: rgb(131, 67, 16); font-weight: bold;">r</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(50, 185, 185);">sum</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">y</span><span style="color: rgb(92, 92, 92);">-</span><span style="color: rgb(131, 67, 16); font-weight: bold;">f</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">x</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">param</span><span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(92, 92, 92);">.^</span><span style="color: rgb(188, 143, 143);">2</span><span style="color: rgb(74, 85, 219);">)</span>;
<span style="color: rgb(176, 24, 19);">endfunction</span>
<span style="color: rgb(176, 24, 19);">function</span> <span style="color: rgb(74, 85, 219);">[</span><span style="color: rgb(131, 67, 16); font-weight: bold;">r</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">dr</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">ind</span><span style="color: rgb(74, 85, 219);">]</span><span style="color: rgb(92, 92, 92);">=</span><span style="text-decoration-line: underline;">costf</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">p</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">ind</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">x</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">y</span>, <span style="color: rgb(131, 67, 16); font-weight: bold;">f</span><span style="color: rgb(74, 85, 219);">)</span>
<span style="color: rgb(131, 67, 16); font-weight: bold;">r</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="text-decoration-line: underline;">residual</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(131, 67, 16); font-weight: bold;">p</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">x</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">y</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">f</span><span style="color: rgb(74, 85, 219);">)</span>;
<span style="color: rgb(131, 67, 16); font-weight: bold;">dr</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(174, 92, 176); text-decoration-line: underline;">numderivative</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(50, 185, 185);">list</span><span style="color: rgb(74, 85, 219);">(</span><span style="text-decoration-line: underline;">residual</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">x</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">y</span>,<span style="text-decoration-line: underline;">fun</span><span style="color: rgb(74, 85, 219);">)</span>,<span style="color: rgb(131, 67, 16); font-weight: bold;">p</span><span style="color: rgb(74, 85, 219);">)</span>;
<span style="color: rgb(176, 24, 19);">endfunction</span>
<span style="color: rgb(74, 85, 219);">[</span>ropt,popt<span style="color: rgb(74, 85, 219);">]</span> <span style="color: rgb(92, 92, 92);">=</span> <span style="color: rgb(50, 185, 185);">optim</span><span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(50, 185, 185);">list</span><span style="color: rgb(74, 85, 219);">(</span><span style="text-decoration-line: underline;">costf</span>,wavenumber,ln_power,<span style="text-decoration-line: underline;">fun</span><span style="color: rgb(74, 85, 219);">)</span>,<span style="color: rgb(74, 85, 219);">[</span><span style="color: rgb(188, 143, 143);">0</span>,<span style="color: rgb(188, 143, 143);">0</span>,<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">mean</span><span style="color: rgb(74, 85, 219);">(</span>wavenumber<span style="color: rgb(74, 85, 219);">)</span>,<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">mean</span><span style="color: rgb(74, 85, 219);">(</span>ln_power<span style="color: rgb(74, 85, 219);">)</span><span style="color: rgb(74, 85, 219);">]</span><span style="color: rgb(74, 85, 219);">)</span>;
<span style="color: rgb(174, 92, 176); text-decoration-line: underline;">plot</span><span style="color: rgb(74, 85, 219);">(</span>wavenumber,<span style="text-decoration-line: underline;">fun</span><span style="color: rgb(74, 85, 219);">(</span>wavenumber,popt<span style="color: rgb(74, 85, 219);">)</span>,<span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">r</span><span style="color: rgb(188, 143, 143);">'</span>,popt<span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">3</span><span style="color: rgb(74, 85, 219);">)</span>,popt<span style="color: rgb(74, 85, 219);">(</span><span style="color: rgb(188, 143, 143);">4</span><span style="color: rgb(74, 85, 219);">)</span>,<span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(188, 143, 143);">xr</span><span style="color: rgb(188, 143, 143);">'</span><span style="color: rgb(74, 85, 219);">)</span></pre>
<p><br>
arctica1963 <<a href="mailto:arctica1963@gmail.com">arctica1963@gmail.com</a>> a écrit :</p>
<blockquote style="border-left:2px solid blue;margin-left:2px;padding-left:12px;" type="cite">
<p>Hello,<br>
<br>
Thanks for the idea and suggestions. Not too sure how to apply it, if you<br>
could give some pointers on the attached data and code. The ultimate idea is<br>
to get the slopes of the straight line segments. Many thanks, Lester<br>
<br>
clear<br>
clf()<br>
// Read data - wavelength (in km)), power, 1 standard deviation<br>
// Unknown data length; 3 columns -default space delimited<br>
<br>
// PSD_wavelength.dat from GMT grdfft radially averaged power spectra<br>
<br>
data = read('PSD_wavelength.dat',-1,3);<br>
<br>
wavelength = data(:,1);<br>
power = data(:,2);<br>
std_dev1 = data(:,3);<br>
<br>
ln_power = log(power);<br>
<br>
wavenumber = 1./wavelength;<br>
f=gcf();<br>
<br>
//plot(wavenumber, ln_power)<br>
<br>
scatter(wavenumber, ln_power,'marker','.')<br>
<br>
a=gce().children;<br>
a.mark_mode = "on"<br>
a.mark_style = 0<br>
a.mark_size_unit = "point"<br>
a.mark_size=3<br>
<br>
xlabel ('wavenumber k (km-1)')<br>
ylabel ('Log (Power)')<br>
<br>
PSD_wavelength.dat<br>
<<a href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/file/t495709/PSD_wavelength.dat" target="_blank">https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/file/t495709/PSD_wavelength.dat</a>><br>
<br>
<br>
<br>
--<br>
Sent from: <a href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html" target="_blank">https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html</a><br>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.scilab">users@lists.scilab</a>.<a href="orghttps://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users" target="_blank">orghttps://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users</a></p>
</blockquote>
<p><br>
<br></p>
</body>
</html>