  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Custom-made linspace and logspace in MATLAB  » matlab » Custom-made linspace and logspace in MATLAB

By : Waleed Qureshi
Date : November 22 2020, 02:59 PM
this one helps. The only difference between linspace and logspace is that they go one step further and take the power of 10 for every element in the linspace array.
As such, you'd simply take your equation for linspace you generated, take the result and raise it to the power of 10. However, with your code, you are relying on the previous result and that is already raised to the power of 10. Therefore, you'll need to take the anti-log to convert the previous result back to a linear form, then use the same logic was used to generate the linspace, then raise it back to the power of 10. Therefore, the relationship is: code :
``````xx[n] = 10^(log10(xx[n-1]) + ((b-a)/(n-1)))
``````
``````xx[n] = xx[n-1] * (10^((b-a)/(n-1)))
``````
``````a = 1; b = 5; n = 7;

x = logspace(1,5,7);
xx = zeros(1,n); xx(1) = 10^a;
for i=2:n
xx(i) = xx(i-1)*(10^((b-a)/(n-1))); %// Change
end
``````
``````>> format long g;
>> x

x =

Columns 1 through 4

10          46.4158883361278          215.443469003188                      1000

Columns 5 through 7

4641.58883361278          21544.3469003189                    100000

>> xx

xx =

Columns 1 through 4

10          46.4158883361278          215.443469003188                      1000

Columns 5 through 7

4641.58883361278          21544.3469003188                    100000
`````` ## Logspace containing specific points (Matlab)

By : user3767776
Date : March 29 2020, 07:55 AM
Hope this helps Perhaps you are doing some sort of plot and what you need is the reference points for those specific values. If that's the case you can also handle the logspace vector separately to the special values, for example, by overlaying two plots.
code :
``````x = logspace(A, B, N);
y = f(x);                       % (whatever function or manipulation you want)

xSpecial = [25, 50, 75];
ySpecial = f(xSpecial);

plot(x, y);                     % plot function curve
hold on;
plot(xSpecial, ySpecial, 'ro'); % overlay special points with red circles
``````
``````xRegular = logspace(A, B, N);        % N regular logspace values
xSpecial = [25, 50, 75];             % special particular values

xCombined = [xRegular, xSpecial];

yCombined = f(xCombined);            % whatever calculation you are doing

yRegular = yCombined(1:N);           % calculated values for xRegular
ySpecial = yCombined(N+1:end);       % calculated values for xSpecial

% e.g. plot with special points
plot(xRegular, yRegular);
hold on;
plot(xSpecial, ySpecial, 'ro');      % red circles indicate special points
`````` ## using linspace in matlab

By : Java777
Date : March 29 2020, 07:55 AM
I hope this helps you . I want to create a vector which runs from 1 to 260 with increments of 360 between every whole number. , Maybe you can just do:
code :
``````n=261;
linspace(1,n,(n-1)*360);
`````` ## does PHP have a function like matlab's linspace?

By : Arslan Khan
Date : March 29 2020, 07:55 AM
To fix this issue I want this to execute the following code in PHP
code :
``````function linspace(\$i,\$f,\$n){
\$step = (\$f-\$i)/(\$n-1);
return range (\$i,\$f,\$step);
}

\$test = linspace(0,3.14159,8);

print_r(\$test);
`````` ## Difference in output between numpy linspace and numpy logspace

By : Peter-Water
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further 2017 update: The numpy 1.12 includes a function that does exactly what the original question asked, i.e. returns a range between two values evenly sampled in log space.
The function is numpy.geomspace
code :
``````>>> np.geomspace(0.02, 2.0, 20)
array([ 0.02      ,  0.0254855 ,  0.03247553,  0.04138276,  0.05273302,
0.06719637,  0.08562665,  0.1091119 ,  0.13903856,  0.17717336,
0.22576758,  0.28768998,  0.36659614,  0.46714429,  0.59527029,
0.75853804,  0.96658605,  1.23169642,  1.56951994,  2.        ])
`````` ## Linspace using matrix input matlab

By : Domen Rupnik
Date : March 29 2020, 07:55 AM
it fixes the issue My question seems wierd, because I know that we can't use a matrix as input in linspace(x1,x2,n) function. But my question is more something like : I have a vector A=linspace(0,Amax,N), and I want to build a serie of vector B_k or big matrix B_k=linspace(0,A(k),N) but without making a for loop that slows down my whole calculation. , Maybe something using interp1, to interpolate something like:
code :
``````[0    0    0    ... 0 ]
[A(1) A(2) A(3) ... A(N)]
``````
``````N = 5;
Amax = 15;
A = linspace(0, Amax, N);

x = [0 1];
y = zeros(2, N);
y(2, :) = A;

B = interp1(x, y, linspace(0, 1, N))
``````
``````B =

0         0         0         0         0
0    0.9375    1.8750    2.8125    3.7500
0    1.8750    3.7500    5.6250    7.5000
0    2.8125    5.6250    8.4375   11.2500
0    3.7500    7.5000   11.2500   15.0000
`````` 