how to solve singular matrix problem?

9 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
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
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)
sub_offsets = 13×1
-0.211697896602533 0.12386548476439 -1.07645045020238 1.28061140149497 -0.156910318982489 1.91942956370997 0.133211427324879 -0.791655877536705 -1.16759248279382 -1.4326781615324
water_l = randn(13,1);
a = fliplr(vander(sub_offsets))
a = 13×13
1 -0.211697896602533 0.0448159994259366 -0.00948745281261109 0.00200847380454555 -0.000425189679803579 9.00117608715221e-05 -1.90553004459914e-05 4.03396702354568e-06 -8.53982333848599e-07 1.8078626381147e-07 -3.82720717835188e-08 8.10211709519208e-09 1 0.12386548476439 0.0153426583159173 0.00190042580987549 0.000235397164198986 2.915758385567e-05 3.61161825884091e-06 4.47354846415251e-07 5.54118249129242e-08 6.86361255451885e-09 8.50164696300429e-10 1.05306062236823e-10 1.30437864475931e-11 1 -1.07645045020238 1.15874557174091 -1.24733219237052 1.34269130002918 -1.44534065439923 1.55583759812386 -1.67478208294222 1.80281992717404 -1.94064632224032 2.0890096072592 -2.24871533221127 2.42063063173582 1 1.28061140149497 1.6399655616389 2.10015859629387 2.6894870433616 3.44418777190185 4.41066612958706 5.64834933373686 7.23334055640992 9.26309838743449 11.8624294081183 15.1911623494654 19.4539757066865 1 -0.156910318982489 0.0246208482031865 -0.00386326514518145 0.000606186166244354 -9.51168647081739e-05 1.49248175819738e-05 -2.34185788754298e-06 3.67461668146028e-07 -5.76585275626308e-08 9.04721795191306e-09 -1.41960185473878e-09 2.22750179855196e-10 1 1.91942956370997 3.68420985004383 7.07158130508559 13.57340221916 26.0531894995821 50.007262154436 95.985417379419 184.237247803097 353.630420169824 678.768683101137 1302.8486772648 2500.72626818249 1 0.133211427324879 0.0177452843699314 0.00236387465920443 0.000314895117369733 4.19476280424573e-05 5.58790340442885e-06 7.44372588257516e-07 9.9158934943298e-08 1.32091032558115e-08 1.75960349838835e-09 2.34399293546163e-10 3.12246644572275e-11 1 -0.791655877536705 0.626719028438411 -0.496145802427361 0.392776740606786 -0.310944015261072 0.24616065726629 -0.194874531143157 0.15427356796169 -0.12213157682543 0.0966861806266775 -0.0765421831696848 0.060595069185772 1 -1.16759248279382 1.36327220587663 -1.5917463795833 1.85851110731574 -2.16998359809067 2.53365653691655 -2.95827832648518 3.45406353601597 -4.03293861974448 4.70882881598253 -5.49799312830411 6.41941544705995 1 -1.4326781615324 2.05256671453184 -2.94066750699807 4.21303011760405 -6.03591624336958 8.64752538671425 -12.3891207728425 17.7496227718388 -25.4294969206515 36.4322848969727 -52.1957389466193 74.7796953138674
rank(a)
ans =
13
a\water_l
ans = 13×1
-2.35759349159405 11.8434405964382 123.871480469065 -481.211603663022 -1422.57087033383 3054.42665671004 7012.57721893851 -2610.6682620545 -8542.3812177498 365.347539146789
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.
A Akhilesh
A Akhilesh il 8 Giu 2021
i am actually trying to find intersection of a curve (station of ship) and a straing line (waterline of ship) i only have points for both the curve and line. it is working with the any randon vlues but when in input the offsets of the ship for calculation i am getting the singular matrix error. the first column in excel file A is my y coordinate and further colums B, C.... are x coordinates of each station like (A, B) plotting all points gives me a curve.
linke the plot in double_body_plan i need to find all intersection the plotted curves and a straingt line

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Sparse Matrices 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!

Translated by