Question

MATLAB question:

Task 4 Many real world objects travel in a jagged manner that is best represented by piecewise functions. For example, the veTask 5 Recall that the following Taylor series is used to approximate Cosine: cos(x)- (2n) You have been tasked with developi

Task 4 Many real world objects travel in a jagged manner that is best represented by piecewise functions. For example, the velocity of a rocket may change sharply when thrusters are enabled or disabled and due to various external factors. The velocity of a rocket can be modelled by v(t) where t represents the time 112-5t 0sts10 1100-5t10StS20 vt) 502( 20)25 20sIs 30 1520e0-30) 0 t >30 otherwise Write a function that takes a start and end time as inputs and returns the vectors v and t. The vector t should contain values between start_t and end t at 0.01 increments. The vector v should contain v(t) for each value in t. function [t, v VPiecewise(start_t, end _t) Use the function in an m-file to plot the velocities for t--5 to 80. Hint: Use if statements to break up the different profile conditions.
Task 5 Recall that the following Taylor series is used to approximate Cosine: cos(x)- (2n) You have been tasked with developing an M-file that allows other engineers to quickly determine the minimum n needed to reduce the truncation error below an error threshold. The truncation error is the absolute error between the approximation and MATLAB's cos) function. Note: You may want to Google the Taylor series to gain a better understanding of it. Your code should do the following: Ask the user to enter an error threshold value (it should work with vectors) Find the number of terms (minimum n) needed so that the truncation error is below the user error threshold for x--2π to 2 Print the minimum n value, the mean truncation error and the maximum truncation error using fprintf. Plot the truncation error against x. 1. 2. 3. 4. Test your code with the following error thresholds: 0.1, 0.01, 1e-10. The answers for the thresholds above should be n-8, 9, 16, respectively. This is a reference to see whether your code is working correctly. Hint: Your code may include both while and for loops and/or a created function to calculate the approximation of Cosine.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

TASK 4:

Programming code in MATLAB;

clc;

clear all;

close all;

function [t, v] = VPiecewise(start_t, end_t)
////////////// Creates two vectors v and t
  
//////////// Creating vector t at increments of 0.01
t = start_t:0.01:end_t;
  
///////////// Initializing vector v
v = [];
  
/////////// Using loop to find v values
for i=1:length(t)
  
/////////  Finding profile conditions
if t(i)>=0 && t(i)<=10
//////////// Updaitng vector
v = [v ((11*t(i)*t(i)) - (5*t(i)))];
elseif t(i)>10 && t(i)<=20
///////////// Updaitng vector
v = [v (1100 - (5*t(i)))];
elseif t(i)>20 && t(i)<=30
////////////////// Updaitng vector
v = [v ((50*t(i)) + ( 2 * ( (t(i)-20) ^ (2.5) )))];
elseif t(i)>30
/////////////// Updaitng vector
v = [v ((1520) * ( exp((-0.1)*(t(i)-30)) ))];
else
v = [v 0];
end % If end
  
end % For loop end
  
end % Function end

Script:

//////////// Plotting travel of a real world objects in a jagged manner
[t, v] = VPiecewise(-5, 80);

///////////// Plotting graph
plot(t, v);
title("Travel of a real world objects in a jagged manner");
xlabel("t");
ylabel("v");

MATLAB O/P:

Thavel of areal voild objedts in a jegged manner 2500 2000 150c 1000 -500 20TASK 5):

MATLAB CODE:

clc;

clear all;

close all;

%%%%%%%%%% the threshold value

Trshold = input('Please enter the error threshold:')

xvl = linspace(-2*pi,2*pi);

cos_trm = ones(size(xvl));

cos_appx = cos_trm;

nvl = 2;

xsqrd = xvl.^2*nvl;

%%%%%%%% Calculation of the approximation

while abs(cos_trm(end)) > Trshold

cos_trm = - cos_trm.*xsqrd./factorial(nvl);

cos_appx = cos_appx + cos_trm;

nvl = nvl + 2;

end

%%%%%%%%%% Calculate truncate error

trun_err = abs(cos_appx - cos(xvl));

fprintf('N value: %d \n',nvl);

fprintf('Mean truncation error: %0.6f \n',mean(trun_err));

fprintf('The error is: %0.6f \n', trun_err);

%%%%%%%%%%%% Perform the plot

plot(xvl,trun_err)

MATLAB O/P:

0 5 1 し0 40

Add a comment
Know the answer?
Add Answer to:
Task 4 Many real world objects travel in a jagged manner that is best represented by piecewise fu...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • The last 3 cases are tests .cpp files to test the code. The language of this...

    The last 3 cases are tests .cpp files to test the code. The language of this code must be C++ because that is the only I am familiar with. Soreland, a software company, is planning on releasing its first C++ compiler with the hopes of putting MiniSoft's Visual C++ out of business (that reminds me of another story). Consequently, Soreland has contracted with the Fruugle Corporation to design and build part of their compiler. Of course, since Fruugle gets all...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 an...

    Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 and 3. It is important to answer the exercises correctly in each labl you should include the appropriate prefix for the unit in the Numerical Value We will not be Volt using the Volt-Ohm meter (VOM) for this lab, so skip the parts that ask for VOM measurements. The parts we You do need to complete Exercises1 Note that in...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT