Find X,Y,Z of this linear
4 ビュー (過去 30 日間)
古いコメントを表示
26.720X + 472.274Y + 791.273Z = 408.162.173.304
42.259X + 567.904Y + 1.358.438Z = 369.152.982.902
49.763X + 593.542Y + 1.405.099Z = 420.198.149.812
1 件のコメント
Stephen23
2023 年 8 月 24 日
移動済み: Stephen23
2023 年 8 月 24 日
There is no need to use the symbolic toolbox, MATLAB offers basic and efficient numeric solvers for this task, e.g.:
format long G
M = [26720,472274,791273; 42259,567904,1358438;49763,593542,1405099]
V = [408162173304; 369152982902; 420198149812]
XYZ = M\V % simpler and faster than slow symbolic operations
Checking the first equation:
M(1,:)*XYZ
回答 (4 件)
Sam Chak
2023 年 8 月 24 日
A = [26 472 791;
42 567 358;
49 593 405]
B = [ 408;
369;
1420]
X = A\B
0 件のコメント
Nathan Hardenberg
2023 年 8 月 24 日
This is very simple to do. I choose diffenent numbers, since I don't know how your "."-delimiters are meant to be.
syms x y z
equations = [
26*x + 472*y + 791*z == 408;
42*x + 567*y + 358*z == 369;
49*x + 593*y + 405*z == 1420;
]
solution = solve(equations, [x y z]);
solution.x
solution.y
solution.z
% To evaluate to a double/float you can do
double(solution.x)
eval(solution.x) % or this
1 件のコメント
Stephen23
2023 年 8 月 24 日
"eval(solution.x) % or this"
Best not. EVAL is not part of the symbolic toolbox and its behavior with symbolic variables is not defined.
Ramtej
2023 年 8 月 24 日
Hi Tiara,
Please refer to Solve System of Linear Equations for the detailed instructions on how to solve system of linear equations using the Symbolic Math Toolbox.
Hope that helps!
0 件のコメント
Paul Bower
2023 年 8 月 24 日
Hi, You could convert the three strings given into a system of equations and solve it using a linear solver. Some code which shows how to do it is given below:
Based on this code:
This is the matrix A:
26720 472274 791273
42259 567904 1358438
49763 593542 1405099
This is the vector b:
1.0e+11 *
4.081621733040000
3.691529829020000
4.201981498120000
This is the solution x:
1.0e+06 *
5.031741885149838
1.290280227764273
-0.424192123520388
I hope this helps. Have a good day. Regards, Paul Bower
% System of equations expressed as strings
str1 = '26.720X + 472.274Y + 791.273Z = 408.162.173.304';
str2 = '42.259X + 567.904Y + 1.358.438Z = 369.152.982.902';
str3 = '49.763X + 593.542Y + 1.405.099Z = 420.198.149.812';
% Initialize matrix A and vector b
A = [];
b = [];
% Convert first string to numbers and write into A & b
[numsArray, lastNum] = extractNumbers(str1);
A = [A; numsArray];
b = [b;lastNum];
% Convert second string to numbers and write into A & b
[numsArray, lastNum] = extractNumbers(str2);
A = [A; numsArray];
b = [b;lastNum];
% Convert third string to numbers and write into A & b
[numsArray, lastNum] = extractNumbers(str3);
A = [A; numsArray];
b = [b;lastNum];
% Display A
disp('This is the matrix A:');
disp(A);
disp('This is the vector b:');
disp(b);
% Solve the system of equations
x = A\b;
disp('This is the solution, x:');
disp(x);
function [numsArray, lastNum] = extractNumbers(inputString)
% Replace the periods (which represent commas or thousands) with empty spaces
cleanedString = strrep(inputString, '.', '');
% Use regular expressions to extract numbers from the string
nums = regexp(cleanedString, '(-?\d+\.?\d*)', 'match');
% Convert the extracted numbers into doubles and store them in an array
numsArray = cellfun(@str2double, nums(1:end-1));
% Extract the last number
lastNum = str2double(nums{end});
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!