How to calculate u for every alpha?
11 views (last 30 days)
Show older comments
Hi Guys,
In my project i have to Write a script that solves the heat conduction equation only for linear basis
functions with Robin boundary conditions. This time different values of α
are to be considered in a simulation. I have to determine for each α the function value
at the left and right end of the interval. Store these values in a matrix. For ¨
α = 2, 5, 10, 15, 20, for example, the matrix could look like the following.
I know how to calculate it for one alpha like alpha = 2, but i dont know how to do it with more alpha and build the matrix. With the for loop i only get the values for alpha=20... This is the code:
...
f= @(x)(0*zeros(size(x)));
alpha = [2,5,10,15,20];
%lineare Basisfunktion
[A]= assemDiffusion1D(nodes, epsilon);
b = assemRightSide1D(f,nodes, "exact");
%Robin RW
for alpha=[2,5,10,15,20]
n = length(A);
b(1)=b(1)+epsilon*alpha/400*271.15;
b(n)=b(n)+epsilon*alpha/400*ul;
A(1,1)=A(1,1)+epsilon*alpha/400;
A(n,n)=A(n,n)+epsilon*alpha/400;
ulinR= A\b;
end
T = [alpha ulinR(1) ulinR(n)]
end
1 Comment
Accepted Answer
Torsten
on 22 Nov 2022
...
f= @(x)(0*zeros(size(x)));
alpha = [2,5,10,15,20];
%lineare Basisfunktion
A = assemDiffusion1D(nodes, epsilon);
b = assemRightSide1D(f,nodes, "exact");
%Robin RW
T = zeros(numel(alpha),3);
for i = 1:numel(alpha)
n = length(A);
b(1)=b(1)+epsilon*alpha(i)/400*271.15;
b(n)=b(n)+epsilon*alpha(i)/400*ul;
A(1,1)=A(1,1)+epsilon*alpha(i)/400;
A(n,n)=A(n,n)+epsilon*alpha(i)/400;
ulinR= A\b;
T(i,:) = [alpha(i),ulinR(1),ulinR(n)]
end
...
5 Comments
Torsten
on 22 Nov 2022
Edited: Torsten
on 22 Nov 2022
To save workspace, this might be a better solution:
...
f= @(x)(0*zeros(size(x)));
alpha = [2,5,10,15,20];
%lineare Basisfunktion
A = assemDiffusion1D(nodes, epsilon);
b = assemRightSide1D(f,nodes, "exact");
A11 = A(1,1);
Ann = A(n,n);
b1 = b(1);
bn = b(n);
%Robin RW
T = zeros(numel(alpha),3);
for i = 1:numel(alpha)
n = length(A);
b(1)=b1+epsilon*alpha(i)/400*271.15;
b(n)=bn+epsilon*alpha(i)/400*ul;
A(1,1)=A11+epsilon*alpha(i)/400;
A(n,n)=Ann+epsilon*alpha(i)/400;
ulinR= A\b;
T(i,:) = [alpha(i),ulinR(1),ulinR(n)]
end
A(1,1) = A11;
A(n,n) = Ann;
b(1) = b1;
b(n) = bn;
...
More Answers (0)
See Also
Categories
Find more on Preprocessing Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!