Question

[30pts] Write a robust, efficient MATLAB script to find the eigenvalues and eigenvectors of a 2 x2 matrix input by the user. can u please on matlab, i have the solution on paper.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

EXPLANATION ::

CODE:

clc;
clear all;close all;
%% Given Data
A=[3,2;4,1];
B=[3,1;2,4];
C=[1,2 ;4,8];
D=[2,3;-3,8];
[eigenA,vectorA]=eigenandvector(A)
[eigenB,vectorB]=eigenandvector(B)
[eigenC,vectorC]=eigenandvector(C)
[eigenD,vectorD]=eigenandvector(D)
%
%% function to calculate
function [eigen,Vector]=eigenandvector(X)
I = eye(rank(X));
% Note X is a 2*2 matrix
% its eigen vales is det(X-lamda*I)=0
% that implies |(X(11)-lamda)*(X(22)-lamda)-X(12)*X(21)|=0
% which is second order equation given by
% (lamda)^2-(X(11)+X(22))*lamda+((X(11)*X(22))-(X(12)*X(21))=0
% if we compare with second order equation
a=1;
b=-(X(1,1)+X(2,2));
c=(X(1,1)*X(2,2))-(X(1,2)*X(2,1));
% whos roots are (-b(+ or -)sqrt((b*b)-(4*a*c))/(2*a)
eigen(1)=(-b+sqrt((b*b)-(4*a*c)))/(2*a);
eigen(2)=(-b-sqrt((b*b)-(4*a*c)))/(2*a);

%% Eigen Vector Calculation
% for each eigen we get one vector as
% M*V=eigen*V
% for vector 1 we get equations as
% (X-eigen*I)*V=0
% by solving

%% For First Vector
m1=(X-(eigen(1)*I));
r1(1)=-m1(1,2)/m1(1,1);
r1(2)=-m1(2,2)/m1(2,1);

if r1(1)>1
Vector1(1)=1;
Vector1(2)=r1(2)*Vector1(1);
Vector1=[Vector1(1);Vector1(2)]
else
Vector1(2)=1;
Vector1(1)=Vector1(2)/r1(2);
Vector1=[Vector1(1);Vector1(2)];
end

%% For second vector
m2=(X-(eigen(2)*I));
r2(1)=-m2(1,2)/m2(1,1);
r2(2)=-m2(2,2)/m2(2,1);

if r2(1)>1
Vector2(1)=1;
Vector2(2)=r2(2)*Vector2(1);
Vector2=[Vector2(1);Vector2(2)]
else
Vector2(2)=1;
Vector2(1)=Vector2(2)/r2(2);
Vector2=[Vector2(1);Vector2(2)];
end
  
%% LETS COMBINE BOTH VECTORS
Vector=[Vector1,Vector2];
end

Add a comment
Know the answer?
Add Answer to:
can u please on matlab, i have the solution on paper. [30pts] Write a robust, efficient...
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