problem doing implicit plotting

Hi, I am trying to make an implicit 3D plot in Matlab. A Matlab Help page says to use the following (as an example):
f = @(x,y,z) x.^2 + y.^2 - z.^2;
interval = [-5 5 -5 5 0 5];
fimplicit3(f,interval)
This works fine. But if I try to complicate things a bit by changing f to:
f = @(x,y,z) x.^2 + y.^2 - z.^2 + x.*y.
then I get the error message "Error: Invalid expression. Check for missing or extra characters".
Any idea what the problem is?
Thank you!

回答 (1 件)

Torsten
Torsten 2024 年 7 月 12 日
移動済み: Torsten 2024 年 7 月 12 日

1 投票

Remove the dot at the end of the expression x.*y.

6 件のコメント

Chris
Chris 2024 年 7 月 12 日
Thank you, Torsten, that worked! But I don't understand why the period needs to be removed because in all other reference to the variables, the period is used.
C
Walter Roberson
Walter Roberson 2024 年 7 月 12 日
x.^2
does not mean "a reference to variable x, squared", (x.)^2 .
It means "the content of x, element-wise-power, 2"
The .^ part is a single operator, element-wise-power and it is different than the ^ operator, which is "matrix power" .
x^2
is x*x which is x matrix-multiply x.
x.^2
is element-by-element squaring of x
Chris
Chris 2024 年 7 月 12 日
Yes, I agree that "x." means element-wise. But it sounds like you are suggesting I use:
f = @(x,y,z) x.^2 + y.^2 + x.*y (last period removed)
So my question is why do we use "." everywhere but for y in the last term "x.y"?
But maybe I am misunderstanding what you are suggesting.
Thanks again!
C
Sam Chak
Sam Chak 2024 年 7 月 12 日
So my question is why do we use "." everywhere but for y in the last term "x.y"?
I guess you were under the impression (learn by example) that the dots in the 1st example are all placed after the variables x, y, z.
For the 2nd example
perhaps writing as follows is clearer for you to follow:
f = @(x,y,z) (x).^2 + (y).^2 - (z).^2 + (x).*(y);
The two-character symbols ".^" (dot-power) and ".*" (dot-product) are math operators in MATLAB.
Sam Chak
Sam Chak 2024 年 7 月 12 日
@Chris, you can see the effect of the dot in this example and comparison.
x = [1 2;
3 4];
% Case 1: element-wise product
y = x.^2
y = 2x2
1 4 9 16
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Case 2a: 2x2 matrix multiplication
y = x^2
y = 2x2
7 10 15 22
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Case 2b: 2x2 matrix multiplication
y = [x(1)*x(1) + x(2)*x(3), x(3)*x(1) + x(4)*x(3)
x(1)*x(2) + x(2)*x(4), x(3)*x(2) + x(4)*x(4)]
y = 2x2
7 10 15 22
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Chris
Chris 2024 年 7 月 12 日
Ahhh, I see. Thank you!
C

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2024 年 7 月 11 日

コメント済み:

2024 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by