Filter löschen
Filter löschen

Simple question. Using 'solve' with vectors

1 Ansicht (letzte 30 Tage)
Joon Jeon
Joon Jeon am 17 Mär. 2012
Hi, I am a matlab rookie. Since I am doing simulation work recently, I start to learn matlab from A, again.
Here is my question. I want to deliver 'x' from the following equation such as log(x)=2/(A-B)
Here, A and B are [10,1] vectors with numbers.
So, my result x should get some matrix like x[10,1].
For this, I programmed like,
CC=zeros(10,1);
for i=1:10
syms x
solve(log(x(i))-(A(i)-B(i))/0.67)
CC(i)=CC(i)+x
end
but the command window keeps saying "??? The following error occurred converting from sym to double: Error using ==> mupadmex Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead."
1. What should I change?
2. If I obtain the result, matlab usually shows in expoenetial terms. How can I order matlab to calculate completely?
Thanks.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Mär. 2012
solve() is not going to store the solutions into "x": it is only going to return the value (which would then be displayed in the command window.)
Because of that, when you get to the CC(i) = CC(i) + x line, x is still a basic symbolic variable whose "value" is its own name, but CC is double precision, so MATLAB tries to convert the name x to a double precision value and of course fails.
Assign the result of solve() to something, and add that something to CC(i) .
You may also need to use a call to double() to force conversion from symbolic numbers to double precision.
  7 Kommentare
Joon Jeon
Joon Jeon am 30 Mär. 2012
It's from the rule of exponential.
X in the log(x) must be positive value when transform to exponential one.
Walter Roberson
Walter Roberson am 30 Mär. 2012
If log(x)-(EU(i)-US(i))/0.67 = 0 (condition to be solved) then
log(x) = (EU(i)-US(i))/0.67 and then
exp(log(x)) = exp((EU(i)-US(i))/0.67) so
x = exp((EU(i)-US(i))/0.67)
and at no point are you taking the log of a negative number.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by