Question

1)

a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code.

b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19



2. The goal of this exercise is (a) al of this exercise is (a) to write a matlab function that uses for loop and preallo- as
MATH 3510 HW 1 (a) (15 points) Write matlab function hw01 p2integral.m) that accepts a containing the values of the integral
0 0
Add a comment Improve this question Transcribed image text
Answer #1


%&Matlab code integral clear all close all loop for finding integration using A fprintf(Integration using formula A\n) for For n=1 the integral value is 0.264241 For n=2 the integral value is 0.160603 For n=3 the integral value is 0.113929 For n=4

%%Matlab code integral
clear all
close all

%loop for finding integration using A
fprintf('Integration using formula A\n')
for i=1:19
    val=int_fun(i);
    fprintf('\tFor n=%d the integral value is %f\n',i,val)
end

%loop for finding integration using B
in_val(1)=1-1/exp(1);

fprintf('Integration using formula B\n')
for i=1:19
    val=i*in_val(i)-(1/exp(1));
    in_val(i+1)=val;
    fprintf('\tFor n=%d the integral value is %f\n',i,val)
end

%function for integration
function val=int_fun(n)

        fun=@(x) x.^n.*exp(-x);
        val=integral(fun,0,1);
      
end

%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...
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