开发者

Trying to solve 2 equations with 2 unknowns symbolically using MATLAB

Trying to solve 2 equations with 2 unknown using MATLAB and it is not liking my input.

Where c is 3.06 + 2.57j, and v is 12:

eq1 开发者_开发知识库= 'c = a/10j'
eq2 = '(6b)/50 + b/10j = a/10j + a/10'

Trying to solve for a and b. Any suggestions of how to properly put these in?


Matlab is screwed up, but the syntax is

sol = solve(eq1,x1,eq2,x2,..);

It would make more sense to make it solve({eq1,eq2,..},{x1,x2,..}) but no, we have to write out all the arguments one by one.

Anyway the trick is that eq1, eq2, .. are symbolic expressions that must be evaluated to zero. So instead of c = a/10j it needs to be eq1=sym('c-a/10j')

So try this:

eq1 = sym('c - a/(10*i)');   % must evaluate to zero
eq2 = sym('(6*b)/50 + b/(10*i) -( a/(10*i) + a/10)'); %must evaluate to zero

sol = solve(eq1,'a',eq2,'b');

a = subs(sol.a,'c',3.06+2.57j)
b = subs(sol.b,'c',3.06+2.57j)

produces a= -25.7000 +30.6000i and b=-20.6639 +29.6967i.

Note that symbolic functions do not understand 10j. It needs to be 10*i. Also the notatation 6b is missing an operator and needs to be 6*b.

Good luck!


Since the problem is linear there is another way to solve it

equs = [eq1;eq2];
vars = [sym('a');sym('b')];
A = jacobian(equs,vars);
b = A*vars - equs;

x = A\b;
c = 3.06+2.57j;
sol = subs(x,'c',c)

with results

sol =
 -25.7000 +30.6000i
 -20.6639 +29.6967i


you need to tell matlab that c,eq1,eq2,a,j (is this not complex?), and b are a symbolic variables. i.e. use the command "syms a b c j eq1 eq2". Then define everything as you have done above minus your single quotes (that's a string!).

then you can just use the 'solve(eq2,'variable you want to solve for'). Easy enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜