Dividing the values of a vector

2 ビュー (過去 30 日間)
Anna Mogilevskaja
Anna Mogilevskaja 2019 年 12 月 3 日
回答済み: Star Strider 2019 年 12 月 3 日
Hello,
I have the following question:
this is my code:
A=[1 1.1; 1.1 1]
l= [sym(2)/sym(3); sym(1)/sym(3)]
w=1
B=[1.09 1.44; 1.44 0.99]
r=linspace(0,1,100)
for k = 1:numel(r)
p(:,k)=(inv(B-(1+r(k))*A))*l
end
The p vector consists out of p1 and p2. After the loop is finished I would like to calculate p1/p2 (also in a loop as I would like to plot p1/p2 against r). Unfortunately, I could not find any references to this case.
Does anyone have a solution for dividing the values of a vector.
Greetings,
Anna
  2 件のコメント
Stephane
Stephane 2019 年 12 月 3 日
Maybe try p(1,:) ./ p(2,:), and then plot(r, p(1,:) ./ p(2,:))
Anna Mogilevskaja
Anna Mogilevskaja 2019 年 12 月 3 日
I habe tried this but it did not work out yet:
A=[1 1.1; 1.1 1]
l= [sym(2)/sym(3); sym(1)/sym(3)]
w=1
B=[1.09 1.44; 1.44 0.99]
r=linspace(0,1,100)
for k = 1:numel(r)
p(:,k)=(inv(B-(1+r(k))*A))*l
end
for k = 1:numel(r)
q(:,k)=(p(1,:)(k)./ p(2,:)(k)
end
figure
plot(r,q)
grid
xlabel('r')
ylabel('q(r)')

サインインしてコメントする。

回答 (2 件)

Shota Kato
Shota Kato 2019 年 12 月 3 日
q can be calculated as follows
q = p(1,:) ./ p(2,:)
or
q(:,k) = p(1,k) / p(2,k)
Then, you can plot q against r.

Star Strider
Star Strider 2019 年 12 月 3 日
Try this:
A=[1 1.1; 1.1 1];
l = [2; 1]/3; % Create As Column Vector
w=1;
B=[1.09 1.44; 1.44 0.99];
r=linspace(0,1,100);
for k = 1:numel(r)
p(:,k)=(B-(1+r(k))*A)\l; % Replace ‘inv’ Call With ‘\’
end
p_div = p(1,:)./p(2,:);
figure
plot(r, p_div)
grid
xlabel('$r$', 'Interpreter','latex')
ylabel('$\frac{p_1}{p_2}$', 'Interpreter','latex')
1Dividing the values of a vector - 2019 12 03.png

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by