creating a script to solve simultaneous equations using matrices

์กฐํšŒ ์ˆ˜: 8 (์ตœ๊ทผ 30์ผ)
Callum Davies
Callum Davies 2022๋…„ 12์›” 23์ผ
ํŽธ์ง‘: Vijay 2022๋…„ 12์›” 26์ผ
i need help to Write a script file to solve a system of simultaneous equations that is written in the form ๐ด๐‘‹ = ๐ต where ๐ด is a square matrix of dimensions ๐‘› ร— ๐‘› The script file must โ€ข Ask for the definition of matrices ๐ด and ๐ต โ€ข Check that matrix ๐ด is square and display an appropriate message if it is not square. โ€ข Check whether a solution exists and display an appropriate message if a solution does not exist. โ€ข Calculate the solution for ๐‘‹ if it exists and display the value of ๐‘‹ with some appropriate text.
I have started but wasnt able to get very far as i am completely stuck and dont know where to go from here. Any help would be greatly appreciated. Here is how far i have gotten with the code.
% Reset the script
clc
clear all
close all
% Get input of the variables of the simultanious equations
a=input("First equation co-efficient of x: ");
b=input("First equation co-efficient of y: ");
c=input("Second equation co-efficient of x: ");
d=input("Second equation co-efficient of y: ");
e=input("First equation content term: ");
f=input("Second equation content term: ");
%set up the matrices
A=[a,b;c,d];
X=[x;y];
B=[e;f];
  ๋Œ“๊ธ€ ์ˆ˜: 2
Callum Davies
Callum Davies 2022๋…„ 12์›” 23์ผ
i know how to do the maths between the matrices but im not sure how to define x and y as their values are unknown. Im also unsure what format to present the output
Dyuman Joshi
Dyuman Joshi 2022๋…„ 12์›” 23์ผ
- How would you check if a matrix is square?
For the equation A*X=B, the solution is X = (A inverse) * B.
- So, to check if a solution exists or not, what is the condition?

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (1๊ฐœ)

Vijay
Vijay 2022๋…„ 12์›” 26์ผ
ํŽธ์ง‘: Vijay 2022๋…„ 12์›” 26์ผ
You can use the program below to solve the equations.
% code section
% Reset the script
clc
clear all
close all
% Get input of the variables of the simultanious equations
a=input("First equation co-efficient of x: ");
b=input("First equation co-efficient of y: ");
c=input("Second equation co-efficient of x: ");
d=input("Second equation co-efficient of y: ");
e=input("First equation content term: ");
f=input("Second equation content term: ");
%set up the matrices
A=[a,b;c,d];
%X=[x;y];
B=[e;f];
X = A\B;
%X will be a matrix of 2 x 1;
In case the solution does not exist you will have "Inf" values in matrix X. you can check that using isfinite method and provide a response a suitable response.
Hope that helps

์นดํ…Œ๊ณ ๋ฆฌ

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!

Translated by