Poissons Equation with Point source
Afficher commentaires plus anciens
Hello everyone :)
in matlab´s Example "Poisson's Equation with Point Source and Adaptive Mesh Refinement" ist a function "circlef" mentioned, that create the point source by returning 1/area for the triangle that contains the origin and zero elsewhere. How do I create such a funtion? Meaning how can I define f differently on specific traingles in the mesh?
Thanks in advance
Hannah
2 commentaires
Dyuman Joshi
le 7 Fév 2024
"How do I create such a funtion?"
Use the description given as its definition.
"Meaning how can I define f differently on specific traingles in the mesh?"
Hannah Burmester
le 7 Fév 2024
Réponses (1)
You can use inpolygon to see if the origin is inside the triangle or not and polyarea to calculate the area of the triangle -
Note - inpolygon() also considers the points that lie ON the edges of the polygon (see the case below).
x = [-2 -1 1];
y = [-2 1 -1];
plot(polyshape(x,y))
hold on
plot(0, 0, '.r', 'MarkerSize', 10)
if inpolygon(0, 0, x, y)
f = 1./polyarea(x,y);
else
f = 0;
end
f
This can be condensed to -
F = inpolygon(0, 0, x, y)./polyarea(x,y)
5 commentaires
If the criteria you use does not involve the points ON the edge to be counted, use this -
x = [-2 -1 1];
y = [-2 1 -1];
[in,on] = inpolygon(0, 0, x, y)
if in & ~on
f = 1./polyarea(x,y);
else
f = 0;
end
f
Which, again, can be condensed to -
F = (in & ~on)./polyarea(x,y)
Dyuman Joshi
le 12 Fév 2024
Torsten
le 12 Fév 2024
I'd simply edit the mentionned MATLAB function:
edit circlef
Isn't that possible ?
Hannah Burmester
le 12 Fév 2024
Dyuman Joshi
le 12 Fév 2024
Modifié(e) : Dyuman Joshi
le 17 Fév 2024
From a cursory glance, I'd say my solution is simpler than whatever is being done here -
type circlef.m
Catégories
En savoir plus sur Electromagnetics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
