Find set of answers for 4 variables in an equation.

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));

Risposte (2)

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 Commenti

Dear Walter,
Thanks, you are right, I have selected just a random simple example for the equation.
In this case, I have this error:
??? Out of memory. Type HELP MEMORY for your options.
Error in ==> ndgrid at 47
x = reshape(x(:,ones(1,prod(s))),[length(x) s]); % Expand x
Error in ==> frac at 16
[X,Y,Z,T] = ndgrid(0.01:0.01:2, -1:0.1:1, 0.0001:0.0001:1, 273:10:900);
Any suggestion!
Your z vector is relatively long; you are running out of memory.
I suggest you ndgrid over x, y, z but not t, and loop over your t values.
As you would be able to analyze the effect of increasing t on the value of the expression you are solving, you might possibly be able to determine a point after which it becomes useless to increase t. For example, if you solve() your equation for t in terms of x, y, z, you could potentially calculate lower and upper bounds for t and so be able to restrict your searching.
Dear Walter,
Thanks.
From my point of view, in this case the answers depends on the length of the defined variables. In another words if by chance the set of answers are in the defined variable, it can find the set, otherwise there is not any set of answers.
Is there other way to solve the equation and find the set of answers independent of the range of variables, then by a filter the sets which are outside of the boundary conditions can be removed!
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
Here is the function:
F=X-(0.55+exp(-2.27.*Y)).*(1+0.005.*log(Z)).*(1+2.578.*T);

Accedi per commentare.

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.

Richiesto:

il 23 Mag 2012

Risposto:

il 19 Feb 2014

Community Treasure Hunt

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

Start Hunting!

Translated by