How can i extrapolate a logspaced vector without changing my old vector?

3 views (last 30 days)
Hey,
Lets say i have a vector
logspace(log10(0.003),log10(0.25),30)
and i want to add 3 or 4 more elements until 0.5. like [0.2945 0.3513 0.4191 0.5000] BUT without changing my old vector elements and maintain my logharithmic scale as properly as possible like my example but more precise.
Is there an easy way to do it ?
Kind regards,
Bünyamin
  1 Comment
Bünyamin Özkaya
Bünyamin Özkaya on 5 Apr 2017
It doesnt have to stop at 0.5 , it could also stop at 0.6
Important for me is maintaining my log-scale. I want to extrapolate "exponentially".

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 5 Apr 2017
Edited: Stephen23 on 5 Apr 2017
I used 8 samples to make the values easier to understand:
>> V = logspace(log10(0.003),log10(0.25),8); % data vector
V =
0.0030000 0.0056432 0.0106152 0.0199678 0.0375606 0.0706537 0.1329038 0.2500000
>> L = log10(V);
>> N = L(end):mean(diff(L)):log10(0.5);
>> Z = [V,10.^N(2:end)] % new vector, extended up to 0.5, same log-scale
Z =
0.0030000 0.0056432 0.0106152 0.0199678 0.0375606 0.0706537 0.1329038 0.2500000 0.4702650
and checking that the log-scale is the same for the new values as the original values:
>> diff(log10(Z))
ans =
0.27440 0.27440 0.27440 0.27440 0.27440 0.27440 0.27440 0.27440
  4 Comments
Stephen23
Stephen23 on 5 Apr 2023
Edited: Stephen23 on 5 Apr 2023
@Aristarchos Mavridis: you could use various approaches, such as COLON (as in my answer) or INTERP1:
format short G
A = zeros(1,100);
A(50:57) = logspace(log10(0.003),log10(0.25),8)
A = 1×100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
X = find(A);
B = 10.^interp1(X,log10(A(X)),1:numel(A),'linear','extrap')
B = 1×100
1.0e+00 * 1.075e-16 2.0221e-16 3.8036e-16 7.1548e-16 1.3459e-15 2.5316e-15 4.7622e-15 8.958e-15 1.685e-14 3.1697e-14 5.9623e-14 1.1216e-13 2.1097e-13 3.9685e-13 7.465e-13 1.4042e-12 2.6414e-12 4.9686e-12 9.3463e-12 1.7581e-11 3.3071e-11 6.2208e-11 1.1702e-10 2.2012e-10 4.1405e-10 7.7886e-10 1.4651e-09 2.7559e-09 5.184e-09 9.7514e-09
Comparing:
A(X)
ans = 1×8
0.003 0.0056432 0.010615 0.019968 0.037561 0.070654 0.1329 0.25
B(X)
ans = 1×8
0.003 0.0056432 0.010615 0.019968 0.037561 0.070654 0.1329 0.25
semilogy([B;A].','-*')

Sign in to comment.

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 5 Apr 2017
V_main = logspace(log10(0.003),log10(0.25),30);
V_add = logspace(log10(.25),log10(0.5),5);
V_out = [V_main,V_add(2:end)];
  1 Comment
Bünyamin Özkaya
Bünyamin Özkaya on 5 Apr 2017
thanks Andrei, However, i cant mantain my log-scale. It doesnt have to stop at 0.5 , it could also stop at 0.6
Important for me is maintaining my log-scale

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!