필터 지우기
필터 지우기

Find set of answers for 4 variables in an equation.

조회 수: 1 (최근 30일)
Victor
Victor 2012년 5월 23일
답변: SooShiant 2014년 2월 19일
Dear all,
I have an equation and the variables are in a specific range.
I am searching for a way to find all sets of answers for this equation.
Should I use loop or solve. Also I have "ln" which does not work with syms Any idea is appreciated.
For example:
% solving x=y*ln(z)+exp(t);
Syms x y z t
x=[0.01:0.1:2];
y=[0:0.1:1];
z=[0.0001:0.001:2];
t=[273:1:900];
[x,y,z,t] = solve(x-y*ln(z)+exp(t));
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 5월 23일
ln() does not work at the MATLAB level. Use log() instead.

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2012년 5월 23일
Your formula is not properly formed. Your x, y, z, and t all have different sizes, and are all row vectors. y*z cannot be computed: "*" is matrix multiplication and the second dimension of y does not match the first dimension of z. We also cannot interpret the "*" as meaning element-by-element operation as there are different numbers of elements in y and z.
I am tempted to suggest what you want is
[X,Y,Z,T] = ndgrid(x,y,z,t);
F = X - Y .* log(Z) + exp(T);
idx = find(F == 0);
[X(idx(:)), Y(idx(:)), Z(idx(:)), T(idx(:))]
However when we look further, we see that this is quite unlikely to have any solutions over the given ranges, as the inputs are all nice decimal values, but log(Z) and exp(T) are going to be transcendental values (i.e., as irrational as you can get within a finite storage number system) and it is improbable that every digit of the first transcendental function will just happen to match the digits of the second transcendental function to cancel everything out to give you a nice exact zero.
Consider the possibility that your inputs are over-specified, that you should be specifying only 3 of them and computing the 4th.
I ran the above computation, and sure enough there are no exact zeros at all. The minimum value computed is about 3.65 * 10^118. This is because of the exp(t) with quite large T. Your maximum y in the expression y*log(z) is 1, so you are looking for places where log(z) = -exp(t). This has a solution in z when z = exp(-exp(t)) and for t = 273 that is exp(-3.65E118) which is smaller than any number you are going to be able to represent in MATLAB or the Symbolic Toolbox.
I would suggest that your formula is probably incorrect.
  댓글 수: 5
Walter Roberson
Walter Roberson 2012년 5월 24일
If you show your actual function, then someone might be able to do some numeric analysis to find constraints on the values.
Before we get to far, please read
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Victor
Victor 2012년 5월 24일
Here is the function:
F=X-(0.55+exp(-2.27.*Y)).*(1+0.005.*log(Z)).*(1+2.578.*T);

댓글을 달려면 로그인하십시오.


SooShiant
SooShiant 2014년 2월 19일
Dear Walter Roberson
Thank you to guide us. I'm new to MATLAB and always have the same problem which Victor mentioned. Now i have a 12 variables function and need to find an answer set.
I used your code in a simple equation which know the answer set but it didn't work.
The equation is: F(x,y)=9x+7y-60=0
The range is: -5<x<10 and -5<y<10
The answer is: If F(x,y)=0 Then [x,y]=[[2,6][9,-3]]
Based on your guide, the way I defined the equation in MATLAB:
x=[-5:1:10];
y=[-5:1:10];
[X,Y]=ndgrid(x,y);
F=9.*x+7.*y-60;
idx=find(F==0);
[X(idx(:)),Y(idx(:))];
As below, If we change the range the way one of the answers come to first row, MATLAB find just that answer for us:
x=[2:1:10];
y=[6:1:14];
[X,Y]=ndgrid(x,y);
F=9.*x+7.*y-60;
idx=find(F==0);
[X(idx(:)),Y(idx(:))];
So the problem has found now. This code calculates F(xi,yj) just for the first row (i=1), so necessarily the only founded result is in the first row. Therefore we should improve our code the way counter calculates F1,1 to F16,16 then MATLAB search within all 16*16 elements of the F matrix. Due to my beginner skills in MATLAB I don't know how to form that matrix, otherwise it seems to be a simple problem for you experts.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by