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--

回答 (1 件)

Youssef  Khmou
Youssef Khmou 2013 年 11 月 17 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2013 年 11 月 17 日
input('Enter Variable Name', 's')
Alex
Alex 2013 年 11 月 17 日
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.
Walter Roberson
Walter Roberson 2013 年 11 月 17 日
編集済み: Walter Roberson 2013 年 11 月 17 日
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 ?
Alex
Alex 2013 年 11 月 17 日
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.
Walter Roberson
Walter Roberson 2013 年 11 月 17 日
Do you have access to the Symbolic Toolbox ?
Alex
Alex 2013 年 11 月 17 日
I do indeed!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

質問済み:

2013 年 11 月 17 日

コメント済み:

2013 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by