Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:13:54+00:00 2026-06-05T16:13:54+00:00

Problem in MATLAB Code for solving desired ‘n’ number of simultaneous equations of the

  • 0

Problem in MATLAB Code for solving desired ‘n’ number of simultaneous equations of the type Ax = b provided that the solving involves the method of upper triangular matrix and the values of A and b are evolved into Aprime and bprime along with the x values.

The problem is to write a code that can solve “n” number of simultaneous equation of the type Ax = b using upper triangulation matrix. The values of A and b are given as matrix in the command window. The code should return Aprime, bprime and x values as the answer when the program is run successfully. The code should also give the output as “Error, Matrix dimensions doesn’t match” (or whatever !) for certain equations ! The code works fine except it shows an error along with the above given Error message.

The code I used is as follows,

function [x, Aprime, bprime]=solved(A,b)
    n = size(A);
    % Assign the size of A to n.
    if (n(1)~= n(2)) || (det(A) == 0)
        % Checking through the determinant method for dimension error.
        disp('ERROR!! Matrix dimensions should agree.')
    else
        for j=1 %:n-1
            % Fix the first value of j to 1.
            if A(j,j)==0
                u=A(j,:);
                A(j,:)=A(j+1,:);
                A(j+1,:)=u;
                %using u as a temperary value "u", to save the row,to swap the positions of two rows.
                v=b(j);
                b(j)=b(j+1);
                b(j+1)=v;
                %using u as a temperary variable "v", to save the row,to interchange the positions of two rows in b matrix.
            end

            for i=j+1:n
                if A(i,j)~=0
                    %If the first number of the particular row  be zero.
                    b(i)=b(j)+(b(i)*(-A(j,j)/A(i,j)));
                    A(i,:) = A(j,:)+(A(i,:)*(-A(j,j)/A(i,j)));
                end
                %After this 'for'loop, the matrix becomes a upper triangle matrix.
            end

            Aprime=A;
            bprime=b;
            x=A\b;
            % Using this command the values of x,y,z can be found.
        end
    end
end

Please provide the suitable correction….

Results as obtained on the command window,

A = [1 1 0;2 1 1;1 2 3]

A =

 1     1     0
 2     1     1
 1     2     3

b= [3;7;14]

b =

 3
 7
14

[x, Aprime, bprime] = solved(A, b)

x =

 1
 2
 3

Aprime =

1.0000    1.0000         0
     0    0.5000   -0.5000
     0   -1.0000   -3.0000

bprime =

3.0000

-0.5000
-11.0000

The second type is,

A = [1 2 3; 4 5 6]

A =

 1     2     3
 4     5     6

b = [7;8;9;10]

b =

 7
 8
 9
10

[x, Aprime, bprime] = solved(A, b)
ERROR!! Matrix dimensions should agree.
Error in solved (line 2)
n = size(A);
Output argument “x” (and maybe others) not assigned during call to
“C:\Users\Hari\Documents\solved.m>solved”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:13:55+00:00Added an answer on June 5, 2026 at 4:13 pm

    Instead of using disp, use the function error to communicate an error. That will tell MATLAB not to try to continue with execution after the error. Plus, the style will match builtin MATLAB errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I faced a problem while writing a code in Matlab that calculates sum of
Iam facing problem in understanding and converting a matlab code into opencv. I want
I have a problem with MATLAB that i cant quite fix. It is throwing
I have a problem in my MATLAB code. Let me first give you some
I have previous experience with MATLAB, but the problem that I face is some
I've got a very odd problem: I've compiled some Matlab code into an assembly.
I have a problem that is driving me nuts. Matlab sees only some of
I have a problem understanding some code fragment from Matlab Signal processing Toolbox fir2()
I am working with some matlab code that processes data (in a Kalman Filter)
I have the following problem using numpy 1.3.0 and MATLAB 7.9.0: the python code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.