Draw a simple shaded surface

I’m now trying to draw a shaded surface like this
70227-surf.png

where the color is set according to a function with respect to the height of the vertices. The Y coordinate (height) of the vertices can be changed dynamically but the other two of them are fixed. I can draw the surface employing mesh and set its color by

material.SetColor("_Color", Color.gray);
renderer.sharedMaterial = material;

but I don’t know how to make it in different colors.

Considering the number of the vertices are large, I need a efficient way to show this.

Can some one give some advices? Thanks!

Assign colours to the vertices in the mesh using the mesh.colors array and then assign a shader that makes use of vertex colours such as this one.