Simulataneous equation solver code
Mostra commenti meno recenti
Hi, I am trying to come up with a simultaneous equation solver that will ask a user for the number of simultanous equations to be solved and the number of coefficients in the simultaneous equations after which a for loop will be used to enter the number of coeffiecients for the number of equations.
Attached is the matlab code
% function for coefficient entry
function s = myfunc_Q2a(x)
s=zeros;
for i=1:x
s(i)=str2double(inputdlg('Enter coefficients: '));
end
end
% script that calls on the above function
g=msgbox('Equation is in the form: x1*a1 + x2*a2 + an*xn= b ');
waitfor(g)
n=str2double(inputdlg('Enter the number of simultaneous equations to be solved: '));
x=str2double(inputdlg('Enter the number of coefficients in the equation: '));
A=zeros;
B=zeros;
s=zeros;
for j=1:n
z(j)=myfunc_Q2a(x);
end
I am receiving an error that states left and right hand side have different number of elements, however when I choose
n=2 and x=1 I dont receive an error.
1 Commento
Ghazwan
il 11 Ott 2022
is it maybe x=1 is the only integer you are entering?
You have a counter i=1:x. x has to be an integer.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!