find minimum value of a two-variable equation on an interval.

3 次查看(过去 30 天)
Hi,
I searched a lot about this question but I still have a trouble in deleting the . when I run the code,
[x y] = meshgrid(1:0.01:2*pi,1:0.01:2*pi);
y = 4*x.^2 + 5*y.^2;
min(min(y));
I dont want copy the equation y every time when I am doing an experiment that have a lot of data.
Thanks!
  2 个评论
dpb
dpb 2020-2-25
Not sure what the real question is...couple comments:
  1. You overwrite y when computing the functional; if want to keep it, write z=... instead.
  2. The idiom min(min()) can be written as either zmin=min(z(:)): or if have release R2018b or later as zmin=min(z,'all');
If those don't match what looking for, explain further...
miaomiao tang
miaomiao tang 2020-2-25
Thanks for your answer, and sorry for the misunderstanding.
My experiment process will generate a two-variable equation so I have to copy and paste the eqaution every time and put the dot in.
There is a dot between every element like .^, so is there anyway I can delet the dot but the equation can still work?
Thanks!

请先登录,再进行评论。

采纳的回答

dpb
dpb 2020-2-25
"...is there anyway I can delet[e] the dot but the equation can still work?"
Ah! Indeed I didn't follow along the nub of the question.
Yes, but not with vectorized inputs; you'd then have to either write the loop explicitly or use arrayfun to process the inputs.
The "dot" operators are mandatory to evaluate the elements of the input arrays as element-by-element operations; otherwise they will be matrix operators which is not what is wanted/needed here.
However, MATLAB is thinking about that for you, already! :) Don't try to swim upstream, instead of trying to evaluate the non-vectorized version, vectorize it instead.
Need more information on the manner in which this "experiment process" is implemented; I'd guess there may be a way to automate the transfer to (say) a text file which could be read into a string which could subsequently be modified as needed by inserting the dot operators via vectorize. The string could then be converted to the functional with str2func

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by