From 5e98f53629c7b622417806515f131c5f8a585876 Mon Sep 17 00:00:00 2001 From: Paco Rilloraza Date: Fri, 31 May 2024 17:05:28 -0400 Subject: [PATCH 1/2] added some surfacefunv routines --- @surfacefunv/imag.m | 10 +++++++ @surfacefunv/real.m | 10 +++++++ @surfacefunv/times.m | 63 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 @surfacefunv/imag.m create mode 100644 @surfacefunv/real.m create mode 100644 @surfacefunv/times.m diff --git a/@surfacefunv/imag.m b/@surfacefunv/imag.m new file mode 100644 index 0000000..6dc98fe --- /dev/null +++ b/@surfacefunv/imag.m @@ -0,0 +1,10 @@ +function fi = imag(f) +%Imag Imaginary part of a SURFACEFUNV + +fi = f; +fi.components{1} = imag(f.components{1}); +fi.components{2} = imag(f.components{2}); +fi.components{3} = imag(f.components{3}); + +end + diff --git a/@surfacefunv/real.m b/@surfacefunv/real.m new file mode 100644 index 0000000..4eab978 --- /dev/null +++ b/@surfacefunv/real.m @@ -0,0 +1,10 @@ +function fr = real(f) +%REAL Real part of a SURFACEFUNV + +fr = f; +fr.components{1} = real(f.components{1}); +fr.components{2} = real(f.components{2}); +fr.components{3} = real(f.components{3}); + +end + diff --git a/@surfacefunv/times.m b/@surfacefunv/times.m new file mode 100644 index 0000000..c710cf1 --- /dev/null +++ b/@surfacefunv/times.m @@ -0,0 +1,63 @@ +function h = times(f, g) +%.* Pointwise multiply for SURFACEFUN(V). +% F.*G divides F by G, where F and G may be SURFACEFUN(V) objects or +% scalars. + +% Empty check: +h = surfacefunv; +if ( isempty(f) || isempty(g) ) + return +end + +if ( isa(f, 'surfacefunv') && isa(g, 'surfacefunv') ) + % Multiply two SURFACEFUNVs: + h.components{1} = f.components{1} .* g.components{1}; + h.components{2} = f.components{2} .* g.components{2}; + h.components{3} = f.components{3} .* g.components{3}; +elseif ( isa(f, 'surfacefunv') && isa(g, 'surfacefun') ) + % Multiply SURFACEFUNV F by SURFACEFUN G: + h.components{1} = f.components{1} .* g; + h.components{2} = f.components{2} .* g; + h.components{3} = f.components{3} .* g; +elseif ( isa(f, 'surfacefun') && isa(g, 'surfacefunv') ) + % Multiply SURFACEFUN F by SURFACEFUNV G: + h.components{1} = f .* g.components{1}; + h.components{2} = f .* g.components{2}; + h.components{3} = f .* g.components{3}; +elseif ( isa(f, 'surfacefunv') && isnumeric(g) ) + if ( isscalar(g) ) + % Multiply SURFACEFUNV F by scalar G: + h.components{1} = f.components{1} .* g; + h.components{2} = f.components{2} .* g; + h.components{3} = f.components{3} .* g; + elseif ( numel(g) == 3 ) + % Multiply SURFACEFUNV F by vector G: + h.components{1} = f.components{1} .* g(1); + h.components{2} = f.components{2} .* g(2); + h.components{3} = f.components{3} .* g(3); + else + error('SURFACEFUNV:times:invalid', ... + 'F and G must be surfacefunv objects, scalars, or constant vectors.'); + end +elseif ( isnumeric(f) && isa(g, 'surfacefunv') ) + if ( isscalar(f) ) + % Multiply scalar F by SURFACEFUNV G: + h.components{1} = f .* g.components{1}; + h.components{2} = f .* g.components{2}; + h.components{3} = f .* g.components{3}; + elseif ( numel(f) == 3 ) + % Multiply vector F by SURFACEFUNV G: + h.components{1} = f(1) .* g.components{1}; + h.components{2} = f(2) .* g.components{2}; + h.components{3} = f(3) .* g.components{3}; + else + error('SURFACEFUNV:times:invalid', ... + 'F and G must be surfacefunv objects, scalars, or constant vectors.'); + end +else + error('SURFACEFUNV:times:invalid', ... + 'F and G must be surfacefunv objects, scalars, or constant vectors.'); +end + +end + From b08f8311308409e5d235c4f27f9267ab589af91b Mon Sep 17 00:00:00 2001 From: Paco Rilloraza Date: Thu, 27 Jun 2024 10:39:17 -0400 Subject: [PATCH 2/2] norm is abs. val. squared --- @surfacefunv/norm.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@surfacefunv/norm.m b/@surfacefunv/norm.m index 79c5247..ffa42d4 100644 --- a/@surfacefunv/norm.m +++ b/@surfacefunv/norm.m @@ -10,6 +10,6 @@ end fc = f.components; -normF = sqrt(fc{1}.^2 + fc{2}.^2 + fc{3}.^2); +normF = sqrt(abs(fc{1}).^2 + abs(fc{2}).^2 + abs(fc{3}).^2); end