Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help not understanding at all the questions below? Write a MATLAB functio

ID: 3632705 • Letter: P

Question

Please help not understanding at all the questions below?

Write a MATLAB function called mypoly that outputs vector x and t where

x(t)=a0+a1 t+ a2 t2 + a3 t3+..aN tN .

The vector t starts at t0 and ends at tf in increments of tinc.

The input to the function should be vector A of coefficients, and vector tinfo=[t0 tinc tf]. A=[a0 a1 a2 .. aN].

2) Write a main program that calls the function mypoly and plots on the same set of axes

a) x(t)=8-2t-8t2+2t3 versus t.

b) y(t)=-t2+5t-4 versus t

for values of t from -5 to 8 in increments of 0.01. Use legends and colors to identify the graphs. Label both axes and include an informative title. Your main program should be saved in an m file called

Explanation / Answer

First part of the question is all about evaluating an equation of the form
x(t) = a0 + a1x + a2 x^2 + ...... + an x^n;
where A = [a0 a1 a2 ..... an]
x is also a vector. here x value is populated using vector tinfo.
x = -5:0.01:8;
it means start with -5, increment 0.01 on each step till it reaches 8.

Second part, simply we are using the function we have developed and evaluating 2 equations. We are drawing a graph with those results. Thats it.

Here is the Matlab code:

function xt = mypoly(A, tinfo)
    t0=tinfo(1);
    tinc = tinfo(2);
    tf = tinfo(3);
    nIndex = 1;
    xt = [zeros(length(t0:tinc:tf),1)]';
    for t = t0:tinc:tf,
       for i = 1: length(A),
       xt(nIndex)= xt(nIndex) + A(i) * (t^(i-1));
       end
       nIndex++;
    end
end

save this function to a separate file called mypoly.m
Open the matlab command prompt and type the following code to plot the results

%tinfo Vector
tinfo = [-5 0.01 8];

%Calculating x(t)
A = [8 -2 -8 2];
xt = mypoly(A,tinfo);

%Calculating y(t)
A = [-4 5 -1];
yt = mypoly(A,tinfo);

t = -5:0.01:8;  
hold on
plot(t,xt,'r');
plot(t,yt,'b');
xlabel('t');
ylabel('x(t) and y(t)');
title('Ploynomials plot');
legend('x(t)','y(t)',2);
refresh

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote