Question

2 Write an M-file to generate E (1/(n+1)Cjwhere, C-1) ifi-j i,j-1 fj >1 Having generated E. for n-20 solve E*x-b where b = [

Can you make matlab solve it?

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

Ans)

%======================MATLAB CODE=============

%Generation of Matrix "E"

n=20;

for i=1:20

for j=1:20

if i==j

C(i,j)=i*(n-i+1);

E(i,j)=(1/(n+1))*C(i,j);

elseif j>i

C(i,j)=C(i,j-1)-i;

E(i,j)=(1/(n+1))*C(i,j);

else

C(i,j)=C(j,i);

E(i,j)=(1/(n+1))*C(i,j);

end

end

end

b=[1:n]'; %MATRIX "b"

a=[E b]; %Coefficient Matrix used for Gauss Elimination below

%Gauss elimination method [m,n)=size(a);

[m,n]=size(a);

for j=1:m-1

for z=2:m

if a(j,j)==0

t=a(j,:);a(j,:)=a(z,:);

a(z,:)=t;

end

end

for i=j+1:m

a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));

end

end

x=zeros(1,m);

for s=m:-1:1

c=0;

for k=2:m

c=c+a(s,k)*x(k);

end

x(s)=(a(s,n)-c)/a(s,s);

end

disp('Gauss elimination method:');

x' %solution vector

===============================================

The solution when you run above code is

2 ans 1.1657e-16 2.3373e-16 4.6876e-16 9.4042e-16 1.1796e-15 1.6579e-15 3.0928e-15 3.8260e-15 2.8866e-15 3.3912e-15 2.9310e-1

Add a comment
Know the answer?
Add Answer to:
2 Write an M-file to generate E (1/(n+1)Cjwhere, C-1) ifi-j i,j-1 fj >1 Having generated E. for n...
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