Consider the functions below both of which are dependent on

Consider the functions below, both of which are dependent on a single input, x. Create a function file that will return the value of both calculations when provided a value (or series of values) of x. Evaluate your functions for times values of 1,2,3 and 4 as well as the vector from 0 to 10 with 1000 elements. Plot your results, adding figure labeling, legends, etc. as necessary. You should present two plots, each with two lines. y_1 = x + 5 y_2 = e^3x + sin (x) Modify your function from 3(b) so that, after evaluating the value of y_1 for a given value of x, an intermediate calculation is performed which divides times by 10 before it is used in evaluating y_2. Evaluate your function at the same points as 3(b) and compare the results.

Solution

b)

x=(1:4)\';                                      %this is to plot the first graph
y1=x+5;                                         
y2=exp(3*x)+sin(x);                     % y1 and y2 are calculated as per the given equations
plot(x,y1,\'r--\')                              % plotting a graph for y1 on x using line splitter
hold on                                       % used to add another plot to the same graph
plot(x,y2)                                    % plotting a graph for y2 on x on the same graph
legend(\'y1\',\'y2\')                          % a legend is created in the graph for discriminating the plots of y1 and y2 on x
y=(0:0.1:10)\';                              % y ranges values from 0 to 10 having 1000 values
x1=y+5;                                       % x1 is same as y1
x2=exp(3*y)+sin(y);                     % x2 is same as y2
plot(y,x1,\'r--\')                               % plotting a graph for x1 on y using line splitter
hold on                                        % used to add another plot to the same graph
plot(y,x2)                                      % plotting a graph for x2 on y on the same graph
legend(\'x1\',\'x2\')                            % a legend is created in the graph for discriminating the plots of y1 and y2 on x

c) Almost same as the previous code, but said intermediate calculation of x is added.

x=(1:4)\';
y1=x+5;
x=x/10;
y2=exp(3*x)+sin(x);
plot(x,y1,\'r--\')
hold on
plot(x,y2)
legend(\'y1\',\'y2\')
y=(0:0.1:10)\';
x1=y+5;
y=y/10;
x2=exp(3*y)+sin(y);
plot(y,x1,\'r--\')
hold on
plot(y,x2)
legend(\'x1\',\'x2\')

 Consider the functions below, both of which are dependent on a single input, x. Create a function file that will return the value of both calculations when pro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site