How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Arty Your Own Question

Arty
Arty, Computer Software Engineer
Category: Programming
Satisfied Customers: 537
Experience:  15+ years of programming, C, C++, Java, PHP, awk, ruby, shell, ASM, Forth, Raptor, M.A.R.I.E, Excel
Type Your Programming Question Here...
Arty is online now
A new question is answered every 9 seconds

I want a pseudo code for the following 1) A pseudo to write

Resolved Question:

I want a pseudo code for the following:

1) A pseudo to write a program that can solve simultaneous equation of two variables
2) Pseudo to write a program that will add 2 matrices together
3) Pseudo code to write a program to subtract two matrices
4) pseudo code to write a program that can solve a quadratic equation.

Please, Its on Qbasic that I want to write the program, so the pseudo code should be one that i can use on Qbasic.
Submitted: 4 years ago.
Category: Programming
Expert:  Arty replied 4 years ago.

 

1) Suppose the following is our linear equation:

A11*X+A12*U=B1

A21*X+A22*Y=B2

 

A11, A12, A21, A22, B1 and B2 are numeric constants

X and Y are unknown (to be found)

 

pseudocode:

 

INPUT A11, A12, B1

INPUT A21, A22, B2

LET D = (A11 * A22 - A12 * A21)

IF D = 0 THEN

PRINT this equation has no unique solution

ELSE

LET X = (B1 * A22 - B2 * A12) / D

LET Y = (B2 * A11 - B1 * A21) / D

PRINT X, Y

END IF

 

2) Pseudo to write a program that will add 2 matrices together

 

A(N, M) and B(N, M) - matrices to add,

C(N, M) - resulting matrix

 

pseudocode:

INPUT N

INPUT M

REM DEFINE MATRIXES

DIM A(N, M)

DIM B(N, M)

DIM C(N, M)

REM READ A MATRIX

FOR ROW = 1 TO N

FOR COL = 1 TO M

INPUT A(ROW, COL)

NEXT COL

NEXT ROW

REM READ B MATRIX

FOR ROW = 1 TO N

FOR COL = 1 TO M

INPUT B(ROW, COL)

NEXT COL

NEXT ROW

REM PERFORM ADDITION

FOR ROW = 1 TO N

FOR COL = 1 TO M

LET C(ROW, COL) = A(ROW, COL) + B(ROW, COL)

NEXT COL

NEXT ROW

REM OUTPUT RESULT

FOR ROW = 1 TO N

FOR COL = 1 TO M

PRINT C(ROW, COL)

NEXT COL

NEXT ROW

 

3) Pseudo code to write a program to subtract two matrices

REM READING CODE FOR A, B, N and M is the same as in 2)

REM SUBTRACT CODE FOLLOWS

FOR ROW = 1 TO N

FOR COL = 1 TO M

LET C(ROW, COL) = A(ROW, COL) - B(ROW, COL)

NEXT COL

NEXT ROW

REM OUTPUT CODE IS THE SAME AS IN 2)

 

4) pseudo code to write a program that can solve a quadratic equation.

let the following quatratic equation

A*X^2 + B*X + C = 0

where A, B, C are constants and X is unknown value

here is a pseudocode

 

INPUT A, B, C

LET D = B * B - 4 * A * C

IF D < 0 THEN

PRINT Equation has no solutions

ELSE IF D = 0 THEN

LET X = -B/(2*A)

PRINT Equation has only one solution

PRINT X

ELSE

LET X1 = (-B + SQRT(D))/(2*A)

LET X2 = (-B - SQRT(D))/(2*A)

PRINT Equation has two solutions

PRINT X1, X2

END IF

 

 

Hope this helps.

 

Regards,

Arty



Edited by Arty on 6/17/2010 at 6:50 AM EST
Customer: replied 4 years ago.

Please I also want the Algorithms and the problem analysis for each problem.

Thank you very much for your understanding

Expert:  Arty replied 4 years ago.

Ok.

 

Algorithms can be expressed with pseudo-code. But they can also be written in simple words. Here is an analysis and algorithm.

 

1) Analysis.

To solve a linar equation, like this:

graphic

where a11, a12, a21, a22, b1, b2 - some fixed numbers and x1, x2 are unknowns,

one should use this formula:

to find X1:

graphic

 

to find X2:

graphic

 

The divisor can't be zero:

graphic

 

So we should check the divisor first, then try to find values.

 

The algorithm is:

- ask user to input known coefficients: a11, a12, a21, a22, b1, b2

- calculate D, that is a11*a22 - a12*a21

- if D is zero - the equation can't be solved

- if D is non zero - calculate x1 and x2 according to the above formula

 

2) Analysis.

 

Only matrices of the same dimentions can be added. Let N is a number of rows, M is a number of columns. Sum of matrices A and B is a matrix C, that has the same dimentions NxM and in the position of any row i and column j there is a sum of corresponding elements (i,j) of matrices A and B.

 

so the algorithm is:

 

- create matrix C with the same dimentions as A and B

- for every row and column of matrix C set element to be equal the sum of appropriate elements of A and B, i.e. C(row, column) = A(row, column) + B(row, column)

 

3) Subtraction of matrices is basically the same as addition. C(row, column) = A(row, column) - B(row, column).

 

4) Quadratic equation looks like:

a*X^2 + b*X +c = 0

 

a, b and c are numbers, X is unknown variable

 

there is a known formula to calculate unknown X:

X = (-b +/- SquareRoot(b^2 - 4*a*c))/(2*a)

 

This equation may have 1, 2 or 0 solutions depending on this expression value: (b^2 - 4*a*c). If it is equal to 0, there is only one solution:

X=(-b)/2*a

If it is below zero - there are no solutions

If it is above zero - there are 2 solutions

X= (-b + SquareRoot(b^2 - 4*a*c))/(2*a)

and

X= (-b - SquareRoot(b^2 - 4*a*c))/(2*a)

 

Algorithm.

- ask user to enter a, b and c

- calculate d = (b^2 - 4*a*c)

- if d<0 print a message that there are no solutions

- if d=0 print a message that there is only 1 solution, X=-B/(2*a)

- if d>0 print a message that there are 2 solutions: X=(-B+square_root(D))/(2*a) and X=(-B-square_root(D))/(2*a)

- exit

 

Regards

Arty

Customer: replied 4 years ago.
Please one final thing before I finally accept the answer. I need the actual code too. Thanks
Expert:  Arty replied 4 years ago.

Hi.

 

Here are all 4 files.

 

Regards,

Arty

Arty, Computer Software Engineer
Category: Programming
Satisfied Customers: 537
Experience: 15+ years of programming, C, C++, Java, PHP, awk, ruby, shell, ASM, Forth, Raptor, M.A.R.I.E, Excel
Arty and 4 other Programming Specialists are ready to help you

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5603
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/unvadim/2010-11-15_210218_avatar.jpg unvadim's Avatar

    unvadim

    Computer Software Engineer

    Satisfied Customers:

    1158
    Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    950
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    864
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/RA/rajivsharma086/2012-6-6_17128_displaypic.64x64.jpg Raj's Avatar

    Raj

    Computer Engg.

    Satisfied Customers:

    860
    BE CS, 4+ Experience in Programming and Database (ERP)
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    590
    11 yrs of programming (PHP, WordPress, XSL, SQL, JavaScript)