Creating user defined variables and solving systems with a script

Hi all, been a while since I needed a question answered, so here goes:
I am creating a script that is used to solve a system of equations defined by a user. The general form of the equation to be solved is K*u=P, where u and P are both column vectors that contain variables, and K is a square matrix the size of the number of rows in u and P. An example would be:
[1,1,1,1;1,1,1,1;1,1,1,1;1,1,1,1][2,u2,u3,2]=[P1,1000,2000,P4]
Where K is generated via user input, and the user is to define all values of u and P. My problem is that I don't know how to have matlab accept variables as a user input, and I don't know how I would solve such a system of equations using Matlab.
Thanks,
--Alex--

Answers (1)

Use input:
K=input(' Enter matrix :\n');
% You enter the K(i,j) as :[4 5 8 7;2 3 6 5] then K is the entered matrix

6 Comments

The input for K is not the issue here, it is the inputs of u and P containing variables, and the solution of the created system of equations that I am having trouble with. All of the examples that I can find online deal with systems of the type Ax=B, where A and B are known and x is a vector of variables, which my system clearly is not of the same form.
When the inputs to u or P contain variables, are the variables intended to represent variables that have already been given a value, or are the variables intended to represent symbols with the output expected to be in the form of symbols ?
Do you have access to the Symbolic Toolbox ?
lets say, for example, there would be 6 values of u, u1, u2, u3, u4, u5, and u6, and there would be 6 corresponding P values. In this situation, the user may have a value for u1, u2, u5, and u6, as well as values for P3 and P4. In this sense, u3 and u4 would be symbols, as would P1, P2, P5, and P6. Sorry if I'm being confusing.
Do you have access to the Symbolic Toolbox ?

Sign in to comment.

Categories

Asked:

on 17 Nov 2013

Commented:

on 17 Nov 2013

Community Treasure Hunt

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

Start Hunting!