Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
getting the contour matrix (x,y & z ) values of ezsurf

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: kalpana

Date: 26 Aug, 2013 10:37:08

Message: 1 of 7


I have one symbolic function " t = func(x,y) " . I am drawing this function using the ezsurf.
I want to find for which values of x & y ; the 't' (function ) value comes very close to zero. for this , i have written the code like the following :

syms x y t
t = func(x,y);
ezsurf(t, [-2,1000,-2,1000]) , hand = findobj(gca,'Type','surface'),
xval =get(hand,'Xdata');
yval = get(hand, 'Ydata'); zval = get(hand, 'Zdata');

But , i am getting zval as 60*60 matrix. I don't think this is the correct method to follow to get the contour matrix of ezsurf. If anyone knows, can you please tell me how to get the contour matrix from ezsurf.
Please tell me.

Thanks in advance.
With regards,
kalpana

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: Steven_Lord

Date: 26 Aug, 2013 13:52:16

Message: 2 of 7



"kalpana " <naidukalpana@yahoo.co.in> wrote in message
news:kvfb4k$n4n$1@newscl01ah.mathworks.com...
>
> I have one symbolic function " t = func(x,y) " . I am drawing this
> function using the ezsurf.
> I want to find for which values of x & y ; the 't' (function ) value
> comes very close to zero. for this , i have written the code like the
> following :
> syms x y t
> t = func(x,y);
> ezsurf(t, [-2,1000,-2,1000]) , hand = findobj(gca,'Type','surface'),
> xval =get(hand,'Xdata');
> yval = get(hand, 'Ydata'); zval = get(hand, 'Zdata');
> But , i am getting zval as 60*60 matrix.

In that case, I would expect xval and yval to be either 60-by-60 matrices or
perhaps 60 element vectors.

> I don't think this is the correct method to follow to get the contour
> matrix of ezsurf. If anyone knows, can you please tell me how to get the
> contour matrix from ezsurf.

Depending on what specifically you mean when you say "the contour matrix of
ezsurf", I think you want to call CONTOUR or CONTOURC on the xval, yval, and
zval matrices you receive after plotting the surface. Alternately, use
MESHGRID to generate X and Y grids over your region of interest, use SUBS to
obtain values for t corresponding to those X and Y values, then call CONTOUR
or CONTOURC on the X, Y, and t matrices.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: kalpana

Date: 27 Aug, 2013 05:50:17

Message: 3 of 7

Thank you very much Mr. Steven Lord for your answer. But, plotting the contour is not what i require. For the specified x & y values, i am plotting " t = func(x,y) " using ezsurf. From the ezsurf plot, i want to get the contour x,y & t values in matrices as the output of ezsurf plot.

It is like this : handl = ezplot(t, [-2, 1000 ,-2,1000]) ,
                   mat1 = get(handl ,'contourMatrix')
Here, we got the contour matrix from the ezplot . right. (Contour means x & y values that define the contour of the function ) . Like this, i want to find the contour values (x,y & t values ) from ezsurf also.

Can you please tell me how i can get the contour values from the ezsurf plot.

Thank you very much,

With best regards,
kalpana







"Steven_Lord" <slord@mathworks.com> wrote in message <kvfmif$sqs$1@newscl01ah.mathworks.com>...
>
>
> "kalpana " <naidukalpana@yahoo.co.in> wrote in message
> news:kvfb4k$n4n$1@newscl01ah.mathworks.com...
> >
> > I have one symbolic function " t = func(x,y) " . I am drawing this
> > function using the ezsurf.
> > I want to find for which values of x & y ; the 't' (function ) value
> > comes very close to zero. for this , i have written the code like the
> > following :
> > syms x y t
> > t = func(x,y);
> > ezsurf(t, [-2,1000,-2,1000]) , hand = findobj(gca,'Type','surface'),
> > xval =get(hand,'Xdata');
> > yval = get(hand, 'Ydata'); zval = get(hand, 'Zdata');
> > But , i am getting zval as 60*60 matrix.
>
> In that case, I would expect xval and yval to be either 60-by-60 matrices or
> perhaps 60 element vectors.
>
> > I don't think this is the correct method to follow to get the contour
> > matrix of ezsurf. If anyone knows, can you please tell me how to get the
> > contour matrix from ezsurf.
>
> Depending on what specifically you mean when you say "the contour matrix of
> ezsurf", I think you want to call CONTOUR or CONTOURC on the xval, yval, and
> zval matrices you receive after plotting the surface. Alternately, use
> MESHGRID to generate X and Y grids over your region of interest, use SUBS to
> obtain values for t corresponding to those X and Y values, then call CONTOUR
> or CONTOURC on the X, Y, and t matrices.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: kalpana

Date: 27 Aug, 2013 06:16:10

Message: 4 of 7

Thank you very much Mr. Steven Lord for your answer. But, plotting the contour is not what i require. For the specified x & y values, i am plotting " t = func(x,y) " using ezsurf. From the ezsurf plot, i want to get the contour x,y & t values in matrices as the output of ezsurf plot.

It is like this : handl = ezplot(t, [-2, 1000 ,-2,1000]) ,
                   mat1 = get(handl ,'contourMatrix')
Here, we got the contour matrix from the ezplot . right. (Contour matrix means x & y values that define the contour of the function ) . Like this, i want to find the contour values (x,y & t values ) from ezsurf also.

Can you please tell me how i can get the contour values from the ezsurf plot.

Thank you very much,

With best regards,
kalpana

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: Steven_Lord

Date: 27 Aug, 2013 13:51:22

Message: 5 of 7



"kalpana " <naidukalpana@yahoo.co.in> wrote in message
news:kvhemp$j92$1@newscl01ah.mathworks.com...
> Thank you very much Mr. Steven Lord for your answer. But, plotting the
> contour is not what i require. For the specified x & y values, i am
> plotting " t = func(x,y) " using ezsurf. From the ezsurf plot, i want to
> get the contour x,y & t values in matrices as the output of ezsurf plot.
> It is like this : handl = ezplot(t, [-2, 1000 ,-2,1000]) , mat1 =
> get(handl ,'contourMatrix') Here, we got the contour matrix from the
> ezplot . right. (Contour means x & y values that define the contour of
> the function ) . Like this, i want to find the contour values (x,y & t
> values ) from ezsurf also.
> Can you please tell me how i can get the contour values from the ezsurf
> plot.

Use the exact procedure I gave you. Note that CONTOUR and CONTOURC can
return the contour matrix, and that's EXACTLY what you are looking for.

*snip*

>> Depending on what specifically you mean when you say "the contour matrix
>> of ezsurf", I think you want to call CONTOUR or CONTOURC on the xval,
>> yval, and zval matrices you receive after plotting the surface.
>> Alternately, use MESHGRID to generate X and Y grids over your region of
>> interest, use SUBS to obtain values for t corresponding to those X and Y
>> values, then call CONTOUR or CONTOURC on the X, Y, and t matrices.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: kalpana

Date: 29 Aug, 2013 06:45:05

Message: 6 of 7

Thank you very much for your answer Mr. steven lord.

Actually, this is what i want to do.
I have two non-linear functions f1(x,y) = 0 & f2(x,y) = 0.
I have to find the solution of f1(x,y) = 0 & f2(x,y) = 0.
For this, i tried to use solve(f1,f2) first. But, it was taking very long time to get the solution (x & y values).
So, i have to use "fsolve" now which requires initial guess for the x & y values.
To get the initial guess, what i have been doing till now is :
               ezsurf(f1 , [-2,1000,-2,1000])
               hand = findobj(gca,'Type','surface')
               x_value=get(hand,'Xdata');
               y_value =get(hand,'Ydata');
               f1_vaue =get(hand,'Zdata');
              [contour_c,handl1] = contour(x_value, y_value, f1_vaue ) % This is what % you have suggested.
But, i want to find the contour_c values (x & y values) for which "f1_vaue" is very close to zero. This, i could not find from the command "[contour_c,handl1] = contour(x_value, y_value, f1_vaue ) ".

Also, since drawing the ezsurf and contour plots take long time, i have dropped the idea of taking the contour matrices from the surface plots .

So, what i am doing now is ::
        syms x y f1 f2
        f1(x,y) % calculation of f1 function
        f2(x,y) % calculation of f2 function
         X = -2 : 0.25 : 55; Y = -2 : 0.25 : 55;
         f1val = subs(f1, {x,y}, {X, Y}) ;
         f2val = subs(f2, {x,y}, {X, Y}) ; % this is also your suggestion.
         fsolve_ind1 = find( abs(f1val ) == min( abs(f1val ) ) );
         fsolve_ind2 = find( abs(f2val ) == min( abs(f2val ) ) );
         fh = matlabFunction([f1 ; f2],'vars',{[x,y]});
        options = optimset('Display','off','TolFun',1e-10);
         [sol_fsolve(:,1), value(:,1), outflag(1)] = fsolve(fh, [X(fsolve_ind1), Y(fsolve_ind1) ] ,options );
         [sol_fsolve(:,2), value(:,2), outflag(2)] = fsolve(fh, [X(fsolve_ind2), Y(fsolve_ind2) ] ,options );

I am taking one of the o/ps ( i.e. sol_fsolve ) as x & y values that has lesser value (i.e. min. of value(:,1) and value(:,2) ).

But, i am getting the final x & y values as : 8.9830e+000 & 1.7937e+001 where as the original x & y values that i should get are : 8.7616e+000 & 2.0232e+001.

That means there is difference in the x & y values that i am supposed to get. This indicates that i am not making the initial guess properly. Can you please tell me how to make the initial guess for x & y values ? ( with out plotting ezsurf because plotting the surfaces takes long time ).

Please please suggest some thing on how to make the initial guess for fsolve ? Am i doing some thing wrong in the above code ?

If you don't mind, please do give some suggestion.

Thank you for your time.

With best regards,
kalpana

Subject: getting the contour matrix (x,y & z ) values of ezsurf

From: Steven_Lord

Date: 29 Aug, 2013 14:07:15

Message: 7 of 7



"kalpana " <naidukalpana@yahoo.co.in> wrote in message
news:kvmqlh$8ot$1@newscl01ah.mathworks.com...
> Thank you very much for your answer Mr. steven lord.
> Actually, this is what i want to do. I have two non-linear functions
> f1(x,y) = 0 & f2(x,y) = 0. I have to find the solution of f1(x,y) = 0 &
> f2(x,y) = 0. For this, i tried to use solve(f1,f2) first. But, it was
> taking very long time to get the solution (x & y values). So, i have to
> use "fsolve" now which requires initial guess for the x & y values. To get
> the initial guess, what i have been doing till now is : ezsurf(f1 ,
> [-2,1000,-2,1000])
> hand = findobj(gca,'Type','surface')
> x_value=get(hand,'Xdata');
> y_value =get(hand,'Ydata');
> f1_vaue =get(hand,'Zdata');
> [contour_c,handl1] = contour(x_value, y_value, f1_vaue ) %
> This is what % you have suggested. But, i want to find the contour_c
> values (x & y values) for which "f1_vaue" is very close to zero. This, i
> could not find from the command "[contour_c,handl1] = contour(x_value,
> y_value, f1_vaue ) ".

You're letting CONTOUR choose the contour levels. Don't. You want the
contour corresponding to z = 0, so specify that.

C = contour(x_value, y_value, f1_value, [0 0]);

> Also, since drawing the ezsurf and contour plots take long time, i have
> dropped the idea of taking the contour matrices from the surface plots .

If what you're looking for is the zero contour, and you don't care about
viewing the surface plot, there's no point in plotting it with EZSURF.

grid = linspace(-2, 2, 128);
[xx, yy] = meshgrid(grid, grid);
z = peaks(xx, yy); % Using a sample function
C = contour(xx, yy, z, [0, 0]);

The documentation for CONTOURC describes the format for the contour matrix
that you can use to extract the points that make up the zero contour.

http://www.mathworks.com/help/matlab/ref/contourc.html

*snip*

> If you don't mind, please do give some suggestion.

The problem you're trying to solve has changed (from getting a contour
matrix to solving a system of nonlinear equations.) Torsten has been helping
you in the new thread you created for that purpose:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/331323

Because of that I think this thread is pretty much closed; please continue
working with Torsten in that other thread.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us