Question

In: Advanced Math

MATLAB please make it simple to understand P4.2.5 Write a script that draws an equilateral triangle...

MATLAB please make it simple to understand

P4.2.5 Write a script that draws an equilateral triangle that is partitioned into four smaller equilateral

triangles by connecting the midpoints of its sides. The four little triangles should be colored

differently.

Solutions

Expert Solution

MATLAB CODE :

%Let's make an equilateral triangle of side 2 with vertices as A(0,0),B(0,2) and C(sqrt(3),1)
V = [0 0; 2 0 ;1 sqrt(3)]; %defining vertices
plot([V(1,1),V(2,1)], [V(1,2),V(2,2)], 'Color', 'k');
hold on
plot([V(2,1),V(3,1)], [V(2,2),V(3,2)], 'Color', 'k');
hold on
plot([V(3,1),V(1,1)], [V(3,2),V(1,2)], 'Color', 'k');
% We'll join the midpoints of each line, coordinates of midpoint of each line
v = [ 1 0 ; 0.5 sqrt(3)/2; 1.5 sqrt(3)/2]; %[1 0 ;% 1*cos 60 1* sin 60; 2 - 1*cos 60 1*sin60]
plot([v(1,1),v(2,1)], [v(1,2),v(2,2)], 'Color', 'k');
hold on
plot([v(2,1),v(3,1)], [v(2,2),v(3,2)], 'Color', 'k');
hold on
plot([v(3,1),v(1,1)], [v(3,2),v(1,2)], 'Color', 'k');
% Using vertices of all 4 triangles, we can fill the triangle with patch command;
% 1st triangle
x1 = [ 0 0.5 1];
y1 = [ 0 sqrt(3)/2 0];
patch(x1,y1,'g')
%2nd triangle
x2 = [ 0.5 1 1.5];
y2 = [ sqrt(3)/2 sqrt(3) sqrt(3)/2];
patch(x2,y2,'b')
%3rd triangle
x3 = [ 1.5 2 1];
y3 = [ sqrt(3)/2 0 0];
patch(x3,y3,'r')
% 4th triangle
x4 = [ 1 0.5 1.5];
y4 = [ 0 sqrt(3)/2 sqrt(3)/2];
patch(x4,y4,'y')

Result:


Related Solutions

In Matlab , Write a script that will print a side-ways triangle pattern of stars in...
In Matlab , Write a script that will print a side-ways triangle pattern of stars in the command window. The script should ask the user how many stars will be between the center of the triangle at the base and the tip of the triangle
Perl Programming Please write a simple to understand Perl script that computes compound interest, based on...
Perl Programming Please write a simple to understand Perl script that computes compound interest, based on input from user for P, n, r and t.
An equilateral triangle is a triangle whose sides are equal. You are to write a class...
An equilateral triangle is a triangle whose sides are equal. You are to write a class called Triangle, using filenames triangle.h and triangle.cpp, that will allow the creation and handling of equilateral triangles, whose sides are integers in the range 1-39. Details: 1. The single constructor for the Triangle class should have 3 parameters: an integer size (required), which is the length of a side; a border character (optional, with a default of '#'); and a fill character (optional, with...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
**MATLAB Code only Please create a MATLAB script that is a TIC-TAC-TOE game. Please keep it...
**MATLAB Code only Please create a MATLAB script that is a TIC-TAC-TOE game. Please keep it simple, but there is no other rules. Thank you.
in a gui ' in java write a program that draws equal a simple fence with...
in a gui ' in java write a program that draws equal a simple fence with vertical, spaced slats backed by two boards. Behind the fence show a simple house support Make sure the in the und. house is visible between the slats in the fence.
Write a MATLAB *function* that draws a spiral by using the plot() command to connect-the-dots of...
Write a MATLAB *function* that draws a spiral by using the plot() command to connect-the-dots of a set of points along the spiral's trajectory. The function should have three input arguments: the number of points along the trajectory, the number of rotations of the spiral, and the final radius of the spiral. The function does not need any output arguments. Use nargin to provide default values for the input arguments. The spiral should begin at the origin. At each step...
P4.2.7 Write a script that draws a bullseye with n concentric rings. The kth ring should...
P4.2.7 Write a script that draws a bullseye with n concentric rings. The kth ring should have inner radius k – 1 and outer radius k. (Thus, the innermost ring is just a radius-1 disk.) The kth ring should be colored white if k is odd and red if k is even. This is a matlab problem
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT