Home Linspace using matrix input matlab
Reply: 1

Linspace using matrix input matlab

John
1#
John Published in 2018-02-14 09:21:03Z

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.

% already defined A
rGC=linspace(0,75e-7,N);
for k=1:N
    r=rGC(k);
    v=linspace(0,A*r,N);
    y=f(r,v);
    INT=trapz(v,y);
    %  The same for 8 more integrals
end
CitizenInsane
2#
CitizenInsane Reply to 2018-02-14 10:47:45Z

Maybe something using interp1, to interpolate something like:

[0    0    0    ... 0 ]
[A(1) A(2) A(3) ... A(N)]

with N rows .... For instance:

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))

Which will give:

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

Not sure it will be any faster than a for loop or that even get the point here :)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31467 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO