Reputation: 137
I'm working with a quadratic surface f(w0,w1) on MATLAB and I used meshgrid to create this. Here's the code:
phi = 0.01;
M = 16;
[w0,w1] = meshgrid(-2:0.1:8 , -10:0.1:0);
f = (0.5+phi)*(w0.^2 + w1.^2) + w0.*w1*cos(2*pi/M) + 2*w1*sin(2*pi/M) + 2;
So I would like to know how can I obtain the value of the function f at the point (-1.9,-0.9), for example.
Thanks
Upvotes: 1
Views: 363
Reputation: 2557
I think the best way should be using annonymous function:
f = @(x,y) (0.5+phi)*(x.^2 + y.^2) + x.*y*cos(2*pi/M) + 2*y*sin(2*pi/M) + 2
f(-1.9,0.9)
x)
Upvotes: 0
Reputation: 1546
Assuming f(-1.9,-0.9) = f(w0, w1)
[row0, col0] = find(w0==-1.9);
[row1, col1] = find(w1==-0.9);
ans = f(row1(1), col0(1));
Upvotes: 1
Reputation: 83417
You could either plug your values directly in the function f:
w0 = -1.9;
w1 = -0.9;
f = (0.5+phi)*(w0.^2 + w1.^2) + w0.*w1*cos(2*pi/M) + 2*w1*sin(2*pi/M) + 2;
or use indices on x and y:
x = -2:0.1:8;
y = -10:0.1:0;
[w0,w1] = meshgrid(x, y);
f = (0.5+phi)*(w0.^2 + w1.^2) + w0.*w1*cos(2*pi/M) + 2*w1*sin(2*pi/M) + 2;
f(find(y==-0.9), find(x==-1.9));
Both methods will return:
ans = 5.1452
Upvotes: 1