logo
down
shadow

Custom-made linspace and logspace in 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


Share : facebook icon twitter icon
Logspace containing specific points (Matlab)

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

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?

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

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

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
Related Posts Related Posts :
  • MATLAB reconstruction of FFT 1D with an image
  • mex error during vl_compilenn
  • MATLAB - Navigation in a struct
  • Misallignment FFT values
  • Random creating binary ID
  • MATLAB 1/Inf default?
  • For-loop exits too early, need help as to why
  • How to show menubar in figure matlab
  • Implicit Euler for stiff equation
  • Access to a object of class in Matlab
  • save a cell array in matlab as .xlsx or .csv file
  • Finding out which function, model or script created a variable in a workspace
  • Create a 10^4 x 3 matrix the columns correspond to various functions
  • adding wait bar to matlab gui
  • Roots of implicit function including integral of modified Bessel function - symbolic variables not compatible with fzero
  • Insert a column of non-numeric data into a cell's column at arbitrary location and shift old data to the right
  • MATLAB: Specify Simulink simulation time using code
  • Matlab: processing audio signal in very small frame sizes makes the audio disappear completely
  • Parsing a CSV file in matlab efficiently
  • Monte Carlo approximation of pi with a sphere
  • Evaluating a constant anonymous function in MATLAB
  • Shift a semi-log chart
  • Solving unknowns of a matrix in Matlab
  • remove cells with zero value in all dimension from processing
  • Error when trying to remove an struct from a vector
  • why digraph not defined in matlab2011?
  • Add arrows in phase space portrait matlab
  • Multidimensional version of "kron" product?
  • Is MatLab worth buying?
  • Extend a line through 3 points matlab
  • How to parse optional inputs in MATLAB?
  • Optimise plotting process of a large matrix
  • Divided differences in MATLAB
  • Vectorizing a summation in Matlab
  • solving linear optimisation in matlab
  • Matlab ocv.dll error The Specified Module Could Not Be Loaded
  • How can I add subtitle for each image below figure in matlab
  • How to Concatenate multiples variables with different size using Matlab ?
  • Extract variables and their values from a cell with comma-delimited data
  • %%G from For Loop changing from index to %G using
  • MATLAB classification trees (fitctree)
  • Computer Algebra Systems that support variable sized matrices
  • Matlab table, column with different sized elements
  • gradient descent MATLAB script
  • Fsolve with variables,
  • concatenate cell-array and matrix in Matlab
  • Construct a simple index matrix from a zero matrix
  • How to read frames from a video MATLAB?
  • Customizing data tips in editor
  • Differentiation using MATLAB
  • convert 3d cell array in 2d cell array
  • MATLAB To File block eval capability
  • Matlab 2015a set mingw64 as mex compiler
  • how can i resize .fig file of matlab plot?
  • get 8 lower significant bits for each element in array
  • filling sparse matrices efficiently matlab
  • How to crop face from landmarks in MATLAB?
  • Count number of rows in a matrix - Matlab
  • Matlab: how to stop command window printing?
  • Looping over a vector efficiently in MATLAB
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co