undocumented expectations and behavior of fimplicit
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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.
fimplict(___)
drawnow
More code
This is not specific to fimplicit, however. All graphics display commands in Matlab work this way.
5 个评论
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!