フィルターのクリア

undocumented expectations and behavior of fimplicit

2 ビュー (過去 30 日間)
Herbert Triceratops
Herbert Triceratops 2021 年 12 月 31 日
コメント済み: Walter Roberson 2022 年 1 月 3 日
I think we should establish here some basic information about fimplicit, since it seems to be very poorly documented.
Maybe the biggest omission is the explicit relationship between x,y,z in fimplicit's parameter f. The documentation says that f should accept matrices x and y and that z should be the same size, but this is insufficient knowledge to extend a function from scalar I/O to matrix I/O. It seems that fimplicit expects corresponding entries of x and y to be paired, i.e. for all i and all j, z(i,j)=f(x(i,j),y(i,j)). I'm not sure why this isn't openly stated in fimplicit's documentation. Perhaps the author was afraid that readers would infer from this that f should be implemented using loops, but the above relationship does not imply any such thing.
Another issue with fimplicit is that it seems to be secretly multithreaded. To plot the curve defined by f(x,y)=0, fimplicit evaluates f many times. According to my experience, code following the call to fimplicit executes in parallel (and non-deterministically) with the evaluations of f. This is extremely undesirable in some situations. Is there a way to disable this?
Thanks!
  7 件のコメント
Herbert Triceratops
Herbert Triceratops 2022 年 1 月 3 日
The original question is about the former, MATLAB's native function that takes a function handle. I never used the symbolic version, but it seems like some but not all of what I said also applies there. For example, I suspect that there is no need to explain the relationship between x,y,z because the user provides an expression and MATLAB itself handles every aspect of the vectorization. Contrast this with the non-symbolic version, where the handle may be to a purely numerical function that does not have a symbolic form, or it is impractical to provide a symbolic form. On the other hand, it may be worth mentioning the asynchronous nature of the function in both.
Regarding the documentation on x,y,z, let me clarify that I fully understand that the missing information can be deduced. Certainly, there are not that many reasonable things one can do with x and y, and if one looks at particular examples of x and y, one will immediately recognize that pairing corresponding entries produces all possible combinations of a list of x-coordinates with a list of y-coordinates, i.e. a grid. None of it is genius-level stuff, I agree. I just feel that one extra line would let everyone skip this step.
Walter Roberson
Walter Roberson 2022 年 1 月 3 日
The documentation says that f should accept matrices x and y and that z should be the same size, but this is insufficient knowledge to extend a function from scalar I/O to matrix I/O.
It might help if you were to give us an example function that can take in matrices x and y that are the same arbitrary size, and give back z the same size, but which is not vectorized so that z(i,j) is not a function of only x(i,j) and y(i,j) ?
The functions that come to mind for me that are not vectorized for output, rely upon particular aspect ratios (such as x and y both being square) or rely upon particular sizes that x and y will always be [e.g.] 7 x 3 so that a matrix-multiply works.
I have certainly seen people have trouble because the very first invocation of a function such as fplot() can be with scalar inputs, as fplot() probes to see whether vectorization works... but I am having trouble thinking of a function that works for arbitrary size arrays but whose output is not corresponding (well, except for functions that use random numbers.)

サインインしてコメントする。

回答 (2 件)

Matt J
Matt J 2021 年 12 月 31 日
編集済み: Matt J 2021 年 12 月 31 日
According to my experience, code following the call to fimplicit executes in parallel (and non-deterministically) with the evaluations of f.
You can use drawnow() to force the plot to display at a particular point in the code, e.g.,
fimplict(___)
drawnow
More code
This is not specific to fimplicit, however. All graphics display commands in Matlab work this way.
  5 件のコメント
Herbert Triceratops
Herbert Triceratops 2021 年 12 月 31 日
I appreciate the attempt, but I'm really looking for somebody from MathWorks to confirm some behavior. All this other stuff is moving farther and farther from the point. It should be clear that one cannot insert interactive pauses, or even timed pauses, into arbitrary code. I could investigate fimplicit.m myself, but that defeats the purpose of this website. I could write my own fimplicit, but that defeats the purpose of MATLAB. I just want somebody to say "yes, this is known behavior, due to X".
Matt J
Matt J 2021 年 12 月 31 日
編集済み: Matt J 2021 年 12 月 31 日
I just want somebody to say "yes, this is known behavior, due to X".
Well, it's definitely known and intentional behavior, as the very existence of the drawnow command indicates. The stated purpose of that command is to sync graphics commands with the rest of the flow of Matlab. The fact that graphics commands can run asynchronously with the rest of Matlab is no secret at all.
You can also see the same behavior with apps. They will also run asynchronously with things that are happening in the command window.
It should be clear that one cannot insert interactive pauses, or even timed pauses, into arbitrary code.
Not to me. When you have asynchronous processes, commands that insert sync points seem like a very natural thing to have.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2021 年 12 月 31 日
Yes, this is known behaviour, due to X.
fimplicit and fplot set up calculations internally, create the axes to draw into, create an internal calculation and drawing thread, and then return control. They refine the search mesh in the background, and fill in details as they go.
In this way, they can be reactive to zoom and pan and resize without the user having to know to call a specific "update fimplicit plot if it needs it" function.

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by