Question

In: Computer Science

A Pythagorean triplet is a set of positive integers (x, y, z) such that x2 +...

A Pythagorean triplet is a set of positive integers (x, y, z) such that x2 + y2 = z2. Write an interactive script that asks the user for three positive integers (x, y, z, in that order). If the three numbers form a Pythagorean triplet the script should a) display the message ‘The three numbers x, y, z, form a Pythagorean triplet’ b) plot the corresponding triangle using red lines connecting the triangle edges. Hint: place the x value on the x-axis and the y value on the y-axis starting at the origin, i.e., start at point (0,0) If the three numbers do not form a Pythagorean triplet the script a) should compute the area of the triangle using Heron’s formula: Area = sqrt( p(p-x)(p-y)(p-z)) where p= (x+y+z)/2 display the message ‘The three numbers x, y, z, correspond to a triangle with are area area’ Make sure that in your script you write comments for the steps above, e.g. % ---- comment ---

Solutions

Expert Solution

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

clc

clear all

close all

format long

x=input('Enter x: ');

y=input('Enter y: ');

z=input('Enter z: ');

if(x^2+y^2==z^2)

disp('The three numbers x, y, z, form a Pythagorean triplet');

x1=linspace(0,x,100);

y1=linspace(0,0,100);

plot(x1,y1);

hold on;

y1=linspace(0,y,100);

x1=linspace(0,0,100);

plot(x1,y1);

x1=linspace(0,x,100);

y1=linspace(y,0,100);

plot(x1,y1);

  

else

disp('The three numbers x, y, z, do not form a Pythagorean triplet')

end

p=(x+y+z)/2;

A=sqrt(p*(p-x)*(p-y)*(p-z));

fprintf('The three numbers x, y, z, correspond to a triangle with are area %f\n',A);

Kindly revert for any queries

Thanks.


Related Solutions

Show that every Pythagorean triple (x, y, z) with x, y, z having no common factor...
Show that every Pythagorean triple (x, y, z) with x, y, z having no common factor d > 1 is of the form (r^2 - s^2, 2rs, r^2 + s^2) for positive integers r > s having no common factor > 1; that is x = r^2 - s^2, y = 2rs, z = r^2 + s^2.
Let x, y, z be a primitive Pythagorean triple with y even. Prove that x+y ≡...
Let x, y, z be a primitive Pythagorean triple with y even. Prove that x+y ≡ x−y ≡ ±1 mod 8.
Show that if (x,y,z) is a primitive Pythagorean triple, then X and Y cannot both be...
Show that if (x,y,z) is a primitive Pythagorean triple, then X and Y cannot both be even and cannot both be odd. Hint: for the odd case, assume that there exists a primitive Pythagorean triple with X and Y both odd. Then use the proposition "A perfect square always leaves a remainder r=0 or r=1 when divided by 4." to produce a contradiction.
If (x,y,z) is a primitive Pythagorean triple, prove that z= 4k+1
If (x,y,z) is a primitive Pythagorean triple, prove that z= 4k+1
Please solve this problem with Python Language. P#2. A Pythagorean triplet is a set of three...
Please solve this problem with Python Language. P#2. A Pythagorean triplet is a set of three natural numbers, a < b < c, for which a2 + b2 = c2 . For example, 32 + 42 = 52. And a + b + c = 3 + 4 + 5 = 12. There exists exactly two Pythagorean triplet for which a + b + c = 300. Find a, b, c. Hints: Level-0 Algorithm: 1. Find the possible ranges of...
The temperature at a point (x, y, z) is given by T(x, y, z) = 100e−x2...
The temperature at a point (x, y, z) is given by T(x, y, z) = 100e−x2 − 3y2 − 7z2 where T is measured in °C and x, y, z in meters. (a) Find the rate of change of temperature at the point P(2, −1, 2) in the direction towards the point (4, −4, 4). answer in °C/m (b) In which direction does the temperature increase fastest at P? (c) Find the maximum rate of increase at P.
The temperature at a point (x, y, z) is given by T(x, y, z) = 300e−x2...
The temperature at a point (x, y, z) is given by T(x, y, z) = 300e−x2 − 3y2 − 9z2 where T is measured in °C and x, y, z in meters. (a) Find the rate of change of temperature at the point P(4, −1, 3) in the direction towards the point (6, −2, 6) (b) In which direction does the temperature increase fastest at P? (c) Find the maximum rate of increase at P.
1) If x, y, z are consecutive integers in order then 9 | (x+y+z) ⟺ 3...
1) If x, y, z are consecutive integers in order then 9 | (x+y+z) ⟺ 3 | y. (Do proof) 2) Let x, y be consecutive even integers then (x+y) is not divisible by 4. (Show proof and state why it was used)
Consider two sets of integers, X = [x1, x2, . . . , xn] and Y...
Consider two sets of integers, X = [x1, x2, . . . , xn] and Y = [y1, y2, . . . , yn]. Write two versions of a FindUncommon(X, Y ) algorithm to find the uncommon elements in both sets. Each of your algorithms should return an array with the uncommon elements, or an empty array if there are no uncommon elements. You do not have to write the ‘standard’ algorithms – just use them. Therefore, you should be...
1.) Prove that Z+, the set of positive integers, can be expressed as a countably infinite...
1.) Prove that Z+, the set of positive integers, can be expressed as a countably infinite union of disjoint countably infinite sets. 2.) Let A and B be two sets. Suppose that A and B are both countably infinite sets. Prove that there is a one-to-one correspondence between A and B. Please show all steps. Thank you! (I rate all answered questions)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT