Solve equation with 2 variables being vectors

Example C=@(A,B) A+B*A A=[1 2 3] B=[4 2 6]
I want C to be a matrix of all possible solutions
Right now I have C as a function and A and B as user inputs
Is there any easier way than writing a loop?
Clarification: C is a very complicated equation with a 2 variables that can have multiple inputs. I want to know all possible solutions. Is there a way to get all possible solutions without nesting loops. I'm making a contour map of 2 inputs and 2 outputs.

3 件のコメント

Justin
Justin 2014 年 5 月 8 日
What do you mean by possible solutions? Do you mean adding only one number from one to only one number to the other one and finding each answer?
Can you explain what the goal of this operation is or some other background?
Nicole
Nicole 2014 年 5 月 9 日
bsxfun does not work because I have 4 variables, c and a are system dependent constants, Ff and Xi are inputs.
Xf=solve(Ff==2*c*a*(Xf/Xi-Xi^2/Xf^2),Xf);
Xf=Xf(1);
Xfs=matlabFunction(Xf);
where Xfs=@(Ff,Xi,a,c)
Justin
Justin 2014 年 5 月 12 日
You should be able to put an array into a symbolic variable and solve for each value of that array. That means you could define Ff and Xi using the meshgrid method in my answer below. You could:
[Xi, Ff] = meshgrid(Xi, Ff)
and then solve with the values of Xi and Ff that are returned which should give you every possible combination.

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

回答 (2 件)

Justin
Justin 2014 年 5 月 8 日
編集済み: Justin 2014 年 5 月 8 日

0 投票

Edited for clarification:
This may do the trick. It has a loop but only one for implementing the function. After it is run the a, b, and c should hopefully be everything you need.
A=[1 2 3];
B=[4 2 6];
[a, b] = meshgrid(A, B);
for i = 1:length(p)
c(i) = C(a(i), b(i));
end
Let me know how that works.
_______________________________________________
OLD STUFF:
I'm not sure if I understand the question right but bsxfun may be useful. bsxfun automatically extends an array along a singleton dimension to match the other array's size. You could use it to get the results you want (I think).
A=[1 2 3];
B=[4 2 6];
bsxfun(@plus, A, B')
ans =
5 6 7
3 4 5
7 8 9
Matt J
Matt J 2014 年 5 月 9 日
編集済み: Matt J 2014 年 5 月 9 日

0 投票

C=bsxfun(@(A,B) A+B.*A, A(:),B(:).')

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2014 年 5 月 8 日

コメント済み:

2014 年 5 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by