Question about the solve function
Show older comments
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
Accepted Answer
More Answers (2)
Walter Roberson
on 21 May 2012
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 Comments
Sean de Wolski
on 21 May 2012
Error using double
Conversion to double from struct is not possible.
Sean de Wolski
on 21 May 2012
S = solve(e1,e2)
double(S.b)
double(S.c)
@Peter: Walter's method is the better way to do it!
Peter
on 21 May 2012
1 Comment
Walter Roberson
on 21 May 2012
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
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!