forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkmodel.m
36 lines (30 loc) · 890 Bytes
/
mkmodel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function [K,F]=mkmodel(n,varargin)
%MKMODEL Assemble model problem with constraints and load vector.
% [K,F]=MKMODEL(N,MATERIAL) assembles "the model problem" on the unit
% square with (N+1)-by-(N+1) node points. The left side is constrained
% to zero displacement, and on the right side a distributed force [1,-1]
% is applied.
%
% Example (solve and plot with 21-by-21 nodes and the default material):
% [K,F]=mkmodel(20);
% U=K\F;
% qdplot(U);
%
% See also: ELMATRIX, ASSEMBLE, QDPLOT.
% Per-Olof Persson <[email protected]>
K=assemble(n,varargin{:});
xfix=ones(n+1,1);
yfix=(1:n+1)';
fix=xfix+(yfix-1)*(n+1);
fix=[fix;fix+(n+1)^2];
K(fix,:)=0;
K(:,fix)=0;
K(fix,fix)=speye(2*(n+1),2*(n+1));
F=zeros(2*(n+1)^2,1);
xload=(n+1)*ones(n+1,1);
yload=(1:n+1)';
load=xload+(yload-1)*(n+1);
h=1/n;
F(load)=h;
F(load([1,end]))=h/2;
F(load+(n+1)^2)=-F(load);