Question about the solve function
3 次查看(过去 30 天)
显示 更早的评论
Let's say I have:
A = [ 1 2 ; 3 4 ]
e1='c*A(1,1)^b=A(1,2)'
e2='c*A(2,1)^b=A(2,2)'
I'm trying to use "solve" to find c and b: solve(e1,e2)
The answer looks like: [ log(A(1, 2)/A(2, 2))/(log(A(1, 1)) - log(A(2, 1))), A(2, 2)/A(2, 1)^(log(A(1, 2)/A(2, 2))/(log(A(1, 1)) - log(A(2, 1))))]
I want it to look like: 0.6309 2.0000
Is "solve" the wrong function for this? How do I do to get a numerical answer?
Best Regards Peter
0 个评论
采纳的回答
更多回答(2 个)
Walter Roberson
2012-5-21
syms b c
A = [ 1 2 ; 3 4 ]
e1 = (c*A(1,1)^b) - (A(1,2));
e2 = (c*A(2,1)^b) - (A(2,2));
double(solve(e1, e2))
2 个评论
Sean de Wolski
2012-5-21
S = solve(e1,e2)
double(S.b)
double(S.c)
@Peter: Walter's method is the better way to do it!
Peter
2012-5-21
1 个评论
Walter Roberson
2012-5-21
Either don't solve() on quoted strings, or learn to use subs()
syms b c
A = [ 1 2 ; 3 4 ; 5 6 ; 7 8 ]
b = zeros(1,size(A,1)-1);
c = b;
for k= 1:size(A,1)-1
S = solve(c*A(k,1)^b-A(k,2),c*A(k+1,1)^b-A(k+1,2));
b(k) = double(S.b);
C(k) = double(S.c);
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!