Cramer's Rule Homework Help

38 visualizaciones (últimos 30 días)
Ryan Albawab
Ryan Albawab el 22 de Abr. de 2015
Comentada: Rakib Seemanto el 1 de Nov. de 2020
Hello,
I am having a lot of trouble with this homework because I am new to matlab. Please help!
Question:
Create a MATLAB script that will read in system of linear equations (SOLE) stored in an excel file (the format will be described in more detail below) and solve for all variables using Cramer's rule. You may assume that you will always be given the same number of equations as there are number of variables, i.e. if there are three variables (x, y, z) then there will be three equations. However, your code should be able to work for an arbitrary size system of linear equations. That means you cannot assume and hardcode the size of the SOLE in your code. Use the size function in Matlab.
I am not looking for the answer, but help and hints on how to go about doing this. This is what I have based on some of my previous knowledge and what I have seen online.
data = xlsread('sole_ex1.xlsx');
x = cramer(A,b);
if det(A) == 0; error('Matrix is invalid'); end
[z,z] = size(A); for g = 1:z;
B = A;
B (:,g) = b;
x(g) = det(B)/det(A);
end
x = x';
Thank You, Ryan Albawab
  1 comentario
Rakib Seemanto
Rakib Seemanto el 1 de Nov. de 2020
how to find the value of x and y by using Cramer’s rule from these equations:
𝑎𝑥+𝑏𝑦=𝑐 and 𝑑𝑥+𝑒𝑦=𝑓 ???

Iniciar sesión para comentar.

Respuesta aceptada

Ahmet Cecen
Ahmet Cecen el 22 de Abr. de 2015
What you wrote in there should work. I am guessing you are actually having trouble with syntax.
data = xlsread('sole_ex1.xlsx');
Here you have to make sure the data you read is in a format you want. I can't help you there without the excel file but you need to explicitly assign A and b. Right now you are just calling the entire batch from excel simply data.This pretty much the only place your code is broken.
x = cramer(A,b);
Get rid of this. I am assuming you tried to define a function here, not necessary according to your homework prompt.
if det(A) == 0; error('Matrix is invalid'); end
z = size(A,1); % Simply better practice.
x = zeros(z,1);
for g = 1:z;
B = A;
B (:,g) = b;
x(g) = det(B)/det(A);
end
  7 comentarios
Ahmet Cecen
Ahmet Cecen el 22 de Abr. de 2015
No, I created a vector 'x' filled with 0s that is the same length as your data. Then I replace each 0 with the actual result later. The code will work just fine if you erase x = zeros(z,1);. Again, a 30 min tutorial on MATLAB will answer every question you can possibly have about this script. There are no tricks involved.
Ryan Albawab
Ryan Albawab el 22 de Abr. de 2015
Sorry for my incompetence, and thank you for your time.
If you could post a link of the tutorial you are speaking of, I would really appreciate it, thank you. Ryan

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by