Question

Solve using MatlabProblem 1. Write a simple loop to list the squares of the first 10 integers. Using a simple while loop, write a script to sum the series 1 2 3 such that the sum is as large as possible without exceeding 100. The program should display how many terms are used in the sum. Write a script that takes as input an integer n and creates the n *n matrix A with (ij)th component given by A(i,j) sin (1/(i +j-1).

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

1.

function A = sq()
A = [];
for i = 1: 10
A = [A i*i];
end
end

= sq.m RUN Vars [1x10] ans 1 function Asq() for i-1:10 end 6 end 10 octave: 12> sq() ans = 4 91625 3649 64 8110e

2.

function terms = sumterms()
sum = 0;
terms = 0;
i = 1;
while true
sum = sum + i;
if sum <= 100
terms = terms + 1;
i = i+1;
else
break;
end
end
end

E sumterms.m RUN Vars # ans 1 function terms= sunterms() terms = 0; 4 while true sum = sum + i; ífsum <= 100 7 termsterms + 1

3.

function X = matrixop(n)
X = zeros(n)
for row = 1:n
for col = 1:n
X(row,col) = sin (1/(row+col-1));
end
end
end

matrixop.m RUN Vars octave: 16> matrixop (5) [5x5] ans 1 function Xmatrixop (n) x-zeros (n) for row1:n 4 for col-1:n X(row, c

Add a comment
Know the answer?
Add Answer to:
Solve using Matlab Write a simple loop to list the squares of the first 10 integers....
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