how to solve singular matrix problem?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
A Akhilesh
il 5 Giu 2021
Commentato: A Akhilesh
il 8 Giu 2021
i am trying to write a code for krlov method for statical stabiltiy of ship, i am using interpolation for finding ordinates of ship. but i am getting error of singular matrix and error with vpasolve please help me.
clear
syms x1
heel=1;
wl=1;
offsets=xlsread('input','offset');
delta=xlsread('input','Displacements');
water_l=offsets(:,1);
for i=1:1:21
sub_offsets(:,i)=offsets(:,i+1);
emg_offsets(:,i)=-offsets(:,i+1);
end
theta=[0;10;20;30;45;60;75;90];
for i=1:1:13
for j=1:1:13
a(i,j)=power(sub_offsets(i),(j-1));
end
end
b=inv(a)*(water_l );
yw=tan(deg2rad(theta))*x1+ delta(1,wl);
y1=b(1,1)+(b(2,1)*x1)+(b(3,1)*x1.^2)+(b(4,1)*x1.^3);
xv = vpasolve(y1-yw==0,x1) % X-Value At Intersection
yv = subs(yw, x1, xv) % Y-Value At Intersection
0 Commenti
Risposta accettata
Walter Roberson
il 5 Giu 2021
You have a number of steps that could be better written. For example,
for i=1:1:21
sub_offsets(:,i)=offsets(:,i+1);
emg_offsets(:,i)=-offsets(:,i+1);
end
can be replaced with
sub_offsets = offsets(:,2:22);
emg_offsets = -subs_offsets;
Then you have
for i=1:1:13
for j=1:1:13
a(i,j)=power(sub_offsets(i),(j-1));
end
end
but notice that sub_offset is a 2D array but you are only using one subscript for it. That is suspicious.
If it is intention, that you want to use the first 13 rows of the first column, then the code could be written more efficiently as
a = sub_offsets(1:13,1) .^ (0:12); %needs R2015b or later
You have
b=inv(a)*(water_l );
but inv() is not high accuracy. You should instead use
b = a\water_l
I suspect that you should have been indexing sub_offsets with two indices when you built a.
Were you trying to construct a Vandermode matrix?
3 Commenti
Walter Roberson
il 5 Giu 2021
https://www.mathworks.com/help/matlab/ref/vander.html and notice it goes in decreasing powers so you need to flip it to match your arrangement
format long g
sub_offsets = randn(13,1)
water_l = randn(13,1);
a = fliplr(vander(sub_offsets))
rank(a)
a\water_l
This test tells us that the process has the potential to work.
Note that the vandermode matrix cannot be full rank if sub_offsets has any duplicates.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!