Azzera filtri
Azzera filtri

I have an idea that I want to write in MATLAB language

1 visualizzazione (ultimi 30 giorni)
I am trying to write a MATLAB code that does the following the user should enter 3 vectors (x1, x2, x3) each has 2 components then evaluate the function f (a function of 2 variables) at the 3 vectors and sort the function values in an ascending order according.
Then name the the higest function value as fh and the lowest as fL. Then name that crossponds to fxh as xh and the number that crossponds to fxL as xL.
What I did so far was:
x1=[8;9]; %the first vector%
x2=[10;11]; %the second vector%
x3=[8;11]; %the 3rd vector%
syms x y
f1=subs(f, {x,y}, [x1(1,1), x1(2,1)]); %value of f at x1%
f2=subs(f, {x,y}, [x2(1,1), x2(2,1)]); %value of f at x2%
f3=subs(f, {x,y}, [x3(1,1), x3(2,1)]); %value of f at x3%
v=[f1 f2 f3]';
v=sort(v); %values of f at an ascending order%
fh=v(3,1); %higest value of f%
fL=v(1,1); %lowest value of f%
Is there a way that makes MATLAB finds the x that crossponds to fh and fL without using the inverse function?
Maybe something like minimizing f over the discrete set S={x1,x2,x2} then find the minimizor of f and assign it name like xL
then do minimization again of f over S-{xL} and find the minimizor and assign it name like xLL
then the only element remaining should be xh.

Risposta accettata

Stephen23 il 1 Gen 2019
Modificato: Stephen23 il 1 Gen 2019
"Is there a way that makes MATLAB finds the x that crossponds to fh and fL ... ?"
You could use indexing:
>> M = [8,9;10,11;8,11] % [X(:),Y(:)]
M =
8 9
10 11
8 11
>> V = (M-[5,6]).^2 * [4;6] % your calculation simplified
V =
>> [Vs,idx] = sort(V);
>> minXY = M(idx(1),:)
minXY =
8 9
>> maxXY = M(idx(3),:)
maxXY =
10 11

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by