2

0.1 ラジアンのスリットを持つメッシュがあります。

mesh = makeSlitMesh(0.1,5)

その内容

        p: [2x188 double]
        t: [3x330 double]
    edges: [2x517 double]
      t2e: [3x330 double]
      e2t: [2x517 double]

get_solution_at_xy関数の私のパラメータ:

>> x = randn(100,1);
>> y = randn(100,1);

以下のコードの関数を実行します

get_solution_at_xy(@(x,y) sin(pi*x) .* sin(pi*y), メッシュ, x, y)

そしてエラーを取得します

Error using TriScatteredInterp
Sample values must be a double array.

Error in get_solution_at_xy (line 18)
    F=TriScatteredInterp(mesh.p(1,:)',mesh.p(2,:)',uh);

配列xyを転置しましたが、それでも同じエラーが発生します。配列は 2 倍です。

このエラーの原因は何ですか?

get_solution_at_xy 関数

% Evaluates the FEM function "uh" defined on "mesh" at the points x,y
% 
% CALLING SYNTAX IS 
%
% function val = get_solution_at_xy(uh,mesh,x,y)
%
%   uh     = FEM function to be evaluated
%   mesh   = trimesh structure on which the FEM function is defined
%   x      = x coordinates of the evaluation points
%   y      = y coordinates of the evaluation points
%
%   val    = value of the FEM function evaluated at the points x,y
%

function val = get_solution_at_xy(uh,mesh,x,y)
    F=TriScatteredInterp(mesh.p(1,:)',mesh.p(2,:)',uh);
    val=F(x,y);
end
4

2 に答える 2

3

からのエラーメッセージの「サンプル値」は、指摘したように double 配列であるとではなくTriScatteredInterp、変数 を参照しています。uhxy

ただし、関数ハンドルをサンプルとして にuh渡しています。次のいずれかを行う必要があります。TriScatteredInterp

  1. [In get_solution_at_xy.m]uhメッシュ ポイントで評価します。

    uhvals = uh(mesh.p(1,:)',mesh.p(2,:)'); F=TriScatteredInterp(mesh.p(1,:)',mesh.p(2,:)',uhvals);

  2. [呼び出し元]無名関数のことは忘れて、数式の代わりに計算値を入力します。

    uhvals = sin(pi*mesh.p(1,:)').*sin(pi*mesh.p(2,:)'); get_solution_at_xy(uhvals, mesh, x, y)

于 2013-09-26T21:17:57.593 に答える
1

それが不平を言っている理由は、関数 TriScatteredInterp が関数をとらず、代わりに 3 番目の引数に double 配列を必要とするためです。これにより、関数コードを変更しなくても問題が解決するはずです。

x = randn(100,1);
y = randn(100,1);
get_solution_at_xy(sin(pi*mesh.p(1,:)).*sin(pi*mesh.p(2,:)), mesh, x, y);
于 2013-09-27T00:43:59.303 に答える