Solving system of linear equations with boundaries, linsolve does not work
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a matrix as follows:
first = [a1, -a1, 0; -a1, a1+a2, -a2; 0, -a2, a2]
second = [u1; u2; u3]
third = [f1;f2;f3]
where: [first] x [second] = [third]
We are given boundary conditions that do not match the linsolve, we know: u1, f2, and f3.
How can I solve this system of linear equations? Any help would be greatly appreciated
0 Kommentare
Antworten (1)
John D'Errico
am 28 Jan. 2018
Bearbeitet: John D'Errico
am 7 Feb. 2023
Linsolve DOES work, IF you use it properly. If not, well, garbage in, garbage out. You cannot use a piece of software without putting the inputs to it in the form it expects.
Apparently you are telling us that {u1, f2, f3} are known? Therefore, I expect that the real unknowns are {u2, u3, f1}?
And what can you possibly mean by "boundary conditions"? Boundary conditions are meaningless in terms of a linear system of equations. You may be thinking of them as pieces of information from whatever problem this system ofequations comes from. But in context of a stsyem of equations, they are just known values. The ykey is a KNOWN value versus something unknown.
Are a1, a2 known values? Since you have not given them to us,, nor the values of the knowns, thus u1,f2,f3, I'll just solve it using symbolic tools.
syms a1 a2
A = [a1, -a1, 0; -a1, a1+a2, -a2; 0, -a2, a2]
Now, you want to solve the linear system for the unknowns u2,u3,f1. We can use symbolic computations.
syms u1 u2 u3 f1 f2 f3
sol = solve(A*[u1;u2;u3] == [f1;f2;f3],u2,u3,f1)
sol =
struct with fields:
u2: [1×1 sym]
u3: [1×1 sym]
f1: [1×1 sym]
sol.u2
ans =
(f2 + f3 + a1*u1)/a1
sol.u3
ans =
(a1*f3 + a2*f2 + a2*f3 + a1*a2*u1)/(a1*a2)
sol.f1
ans =
- f2 - f3
However, you COULD have used linsolve, IF you formulated and rearranged the system of equations properly. Be careful, because A is a singular matrix. Just restucture the problem so that all of your unknowns are in one vector, multiplied by a matrix. Put all of the known information on the right hand side.
That your problem does not match linsolve just means you need to move the information around. You have these equations:
a1*u1 -a1*u2 = f1
-a1*u1 + (a1+a2)*u2 -a2*u3 = f2
-a2*u2 + a2*u3 = f3
A simple rule when you want to solve such a system of equations is to move everything you know to one side of the equalities, and everything you don't know to the other side. See how it works here. u1 is known. So move those terms to the right of the equality. f1 is unknown. So move it to the left side.
-f1 -a1*u2 = a1*u1
(a1+a2)*u2 -a2*u3 = f2 + a1*u1
-a2*u2 + a2*u3 = f3
Surely, you would agree I have done what the rule tells me to do? Now solve that, using linsolve, if you wish. We will need to factor out the unknowns into a vector.
Ahat = [-1,-a1,0; 0,a1+a2,-a2; 0,-a2,a2];
RHS = [a1*u1;f2+a1*u1;f3];
% The unknowns will be in a vector, in this order: [f1;u2;u3]
unknowns = linsolve(Ahat,RHS);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!