Question

Question 2 We define, for a given integer m, 1 sism, h Xi = (i – 1) m-1 1 X1 1 X2 The mx2 matrix X is defined as: X = 1 Xm [

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab function myfunc.m for the problem

function res = myfunc(m,v)
% Input
% m: a scalar
% v: a colum vector of size 2x1
% Output
% res: a scalar
h = 1/(m-1); % Computing the value of h
i = 1:m; % crreating i vector varies from 1 to m
x = (i-1)*h; % Calculating x vector
X = [ones(m,1),x']; % Create X using x
Y = 0.1*sin(pi*x'); % Create Y using x
% Now compute the res
res = ((Y')*Y)-(2*((v')*((X')*Y)))+((v')*(((X')*X)*v));
end

Script to call the function to compute res

clc; clear; % Clearing the command window and workspace
m = 20; % setting the value of m as 20
v = [1;1]; % seting the value of v
res = myfunc(m,v); % calling the function to calculate res
% printing the result
fprintf('For m = %d and v = [%d; %d], the res = %0.4f.',m,v,res);

Screen Print of the code

1 2 3 4 5 6 function res = myfunc(mv) % Input % m: a scalar % v: a colum vector of size 2x1 % Output % res: a scalar h = 1/(m

1 2 - 3 clc; clear; % Clearing the command window and workspace m = 20; % setting the value of m as 20 V = [1,1]; % seting th

OUTPUT of the code

COMMAND WINDOW For m = 20 and v = [1; 1], the res = 43.3166.

Add a comment
Know the answer?
Add Answer to:
Question 2 We define, for a given integer m, 1 sism, h Xi = (i –...
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
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