how to solve multiple equations that use the same variable but different values

5 ビュー (過去 30 日間)
Ryan Nguyen
Ryan Nguyen 2020 年 9 月 2 日
コメント済み: Adam Danz 2020 年 9 月 12 日
I have a question that involves finding the velocity through two different equations. The problems calls to use both equations. Those equations use a variable 'c' to solve, however, 'c' has two different values. We are suppose to use a speicfic value of 'c' for each equation.
For example:
c = 3, 10
v(1) = (4c +150)/2
v(2) = (6c -23)*8
when I type it in like this, it only solves for c=3 and v(1), but doesnt solve for c=10 and v(2)
  2 件のコメント
Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020 年 9 月 3 日
c =[ 3; 10];
% first column for c1, second column for c2
v(:,1)=2.*c+75
v(:,2)=48.*c-184
J. Alex Lee
J. Alex Lee 2020 年 9 月 3 日
The problem is unclear...if I follow literally what you say, I end up with
% c = 3, 10
v(1) = (4*3 +150)/2
v(2) = (6*10 -23)*8
these aren't equations to solve, just assignments into elements of v...

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

回答 (2 件)

Adam Danz
Adam Danz 2020 年 9 月 4 日
The goal is not clear but it seems like the question can be answered by indexing c.
c = [3, 10]
v(1) = (4*c(1) +150)/2;
v(2) = (6*c(2) -23)*8;
If this does not address the goal, please clarify.

BOB MATHEW SYJI
BOB MATHEW SYJI 2020 年 9 月 12 日
Hi, I have created a function find_velocity in which the input is c (In this case c=[3,10]). The output v is a 2*2 matrix in which first column gives the value of v(1) and v(2) respectively at c=3. and second column gives the value of v(1) and v(2) respectively for c=10. Hope this helps.
function v = find_velocity(c)
for i=1:length(c)
v1(i)=(2*c(i))+75;
v2(i)=((6*c(i))-23)/8;
end
v=[v1; v2];
end
  1 件のコメント
Adam Danz
Adam Danz 2020 年 9 月 12 日
The vectorized version where c is a row vector,
v = [(4.*c +150)./2; ((6.*c)-23)./8;];

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by