Solve system of equations dependent on parameter

18 views (last 30 days)
I want to solve a system of linear equations in Matlab. The problem is that this system will have a non-unique solution in general ( so the Nullspace is non-trivial) and this system depends on a parameter beta(non-zero!), that I don't want to specify in advance. Hence, I want to have the solution in terms of this parameter. Is MATLAB able to do this? In what way would I need to enter the equations and the parameter and which command would I need to use so that Matlab gives me all solutions? Could anybody here give me an idea how I would need to do this? Thanks to all of you.
  4 Comments
Simon Becker
Simon Becker on 10 May 2014
@Matt J The solution is the set of all solutions. @ StarStrider I don't think so, would this help?
Star Strider
Star Strider on 10 May 2014
The Symbolic Toolbox might make it possible for you to simplify it more easily than manually.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 10 May 2014
Edited: Matt J on 10 May 2014
Even if there is a closed form solution for what you're after, I suspect it's going to offer little more benefit than just running the numerical solver for each beta that you want to examine.
If we even just restrict ourselves to square non-singular A(beta), the solution to A(beta)*x=b has a known closed form
x(beta)=Cofactor(A(beta)).'/det(A(beta))
For dimensions large enough where a closed form might be beneficial, the time needed just to compute det(A(beta)) will be almost as long as needed to solve the system numerically, e.g.,
>> A=rand(2000); tic;det(A);toc ; tic; A\A(:,1);toc
Elapsed time is 0.165891 seconds.
Elapsed time is 0.215790 seconds.
That's assuming, at least, that there isn't a major simplification in the form of the determinant due to the specifics of the dependence on beta.
When A is non-singular and you additionally want to use a formula for the null-space as a function of the matrix entries, I think there's a chance that the formula will be so complicated as to offer no benefit.
  3 Comments
Matt J
Matt J on 10 May 2014
Edited: Matt J on 10 May 2014
You can write mfiles or anonymous functions that generate system data as a function of beta. Here's an example of such a function and a potential solver
function [A,b]=mydata(beta)
A=[1 0; 0 beta];
b=[1;beta];
end
function mysolver(A,b)
if rank([A,b])>rank(A)
disp 'There are no solutions'; return
end
x=pinv(A)*b;
N=null(A);
if isempty(N)
disp 'The unique solution is'
x,
else
disp 'Any vector of the form x+N*c is a solution where'
x,N
end
end
and now, as examples of usage,
>> [A,b]=mydata(1); mysolver(A,b);
The unique solution is
x =
1
1
>> [A,b]=mydata(0); mysolver(A,b);
Any vector of the form x+N*c is a solution where
x =
1
0
N =
0
1
Matt J
Matt J on 10 May 2014
Edited: Matt J on 10 May 2014
You could also make mysolver() a function of beta directly
function mysolver(beta)
[A,b]=mydata(beta);
if rank([A,b])>rank(A)
disp 'There are no solutions'; return
end
x=pinv(A)*b;
N=null(A);
if isempty(N)
disp 'The unique solution is'
x,
else
disp 'Any vector of the form x+N*c is a solution where'
x,N
end
end

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 10 May 2014
You will need the symbolic toolbox for anything more than what you can do with pencil and paper. Easy enough with it though.
syms x y z beta
xyz = solve(2*x + beta*y + 2*beta*z - 2,-x + 3*y + 2*z - beta,x,y,z)
Warning: 2 equations in 3 variables. New variables might be introduced.
> In /Applications/MATLAB_R2014a.app/toolbox/symbolic/symbolic/symengine.p>symengine at 56
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 170
Warning: The solutions are parametrized by the symbols:
z1 = C_
> In solve at 190
xyz =
x: [1x1 sym]
y: [1x1 sym]
z: [1x1 sym]
The solution is in xyz, where each of x,y,z depend on the unknown parameter z1.
xyz.x
ans =
-(beta^2 + 4*z1*beta - 6)/(beta + 6)
xyz.y
ans =
(2*(beta - 2*z1 - beta*z1 + 1))/(beta + 6)
xyz.z
ans =
z1
  1 Comment
Simon Becker
Simon Becker on 10 May 2014
thanks, this is helpful. But in my case, I cannot just write down the equations the way you did. I need to define a matrix A that has entries dependent on the parameter beta and solve Ax = b, where b also depends on beta. So how would I define A and b then and solve this system?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!