フィルターのクリア

how to find values of X and Y that satisfy condition Z(X,Y)>a

15 ビュー (過去 30 日間)
Tim White
Tim White 2016 年 10 月 4 日
回答済み: Giovanni Mottola 2016 年 10 月 4 日
Dear Pros, I'm very new to Matlab, and I'm a chemist not a computer science guy or engineer so be gentle with me please :). I have a rather complicated function of 2 variables Z=f(X,Y). I wish to find all the X and Y combinations (all real and positive numbers) at which z is above a certain value, so I'm looking to solve the inequity Z > a for X and Y. X and Y are vectors so I'm looking for an output that would be a set of X and Y pairs that satisfy the condition. Preferably these X and Y's and a would be arguments in a function that would describe an analytic solution (as an equation for a sphere segment would define the solution of all the points in a sphere above a certain longitude). Thanks for your help in advance, Tim

回答 (1 件)

Giovanni Mottola
Giovanni Mottola 2016 年 10 月 4 日
Is it something like this you're looking for?
function [vec_pairs, num_pairs] = find_greater(X, Y, a)
len_X=length(X);
len_Y=length(Y);
num_pairs=0; % number of such pairs that have been found
for i=1:len_X
for j=1:len_Y
z=f(X(i), Y(j)); % insert name of your function, as defined in another .m file
if z>a
num_pairs=num_pairs+1;
vec_pairs(num_pairs, :)=[X(i), Y(j)];
end
end
end
end
Example:
X=[-1 -0.5 0 0.5 1];
Y=[-1 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1];
The function f is defined in another .m file:
function z=f(x, y)
z=sqrt(1+x^2+y^2);
end
Calling the function from the command window:
[v, n]=find_greater(X, Y, 1.5)
Results:
v= -1.0000 -1.0000
-1.0000 -0.7500
-1.0000 0.7500
-1.0000 1.0000
1.0000 -1.0000
1.0000 -0.7500
1.0000 0.7500
1.0000 1.0000
n= 8

カテゴリ

Help Center および File ExchangeMathematics and Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by