How to call a concrete number of a vector inside a function
5 views (last 30 days)
Show older comments
Hi,
I have a position vector: x= [ 1 2 3 4 5 6 7] and an area vector A= [10 11 12 13 14 15]
I am trying to create a function called:
function [M] = Area_jumps (A1, A2, c1, c2, rho1, rho2, x1, s)
a = A2/A1.*rho1.*c1/(rho2.*c1);
t1 = s*x1./c1;
t2 = s*x1./c2;
M = [-exp(-t1), -exp(t1), +exp(-t2), +exp(t2);
-exp(-t1), +exp(t1), +a.*exp(-t2), -a.*exp(t2)];
end
% (where c is the speed of sound and rho is the density)
A1 and A2 represent the position, 1 and 2. But I want to do this for the 5th first position of the vector.
How can I do this?
Thank you
0 Comments
Answers (1)
Steven Lord
on 15 May 2020
It's not completely clear to me how the variables A1, A2, and x1 in your function are related to your A and x vectors. It's also not clear what "the 5th first position of the vector" means.
But taking an educated guess at where the problem lies, you may want to use element-wise division between A2 and A1.
A2 = 10:16;
A1 = 1:7;
sol1 = A2./A1 % sol1(k) is A2(k) divided by A1(k)
sol2 = A2/A1 % least-squares solution to sol2*A1 = A2, so a scalar
3 Comments
Steven Lord
on 15 May 2020
A = 10:15;
m = 2;
p = 1:m+3;
k = p+1;
I think this is what you're looking for.
ratio = A(k)./A(p) % Note the ./ instead of /
See Also
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!