The least square with changing number of lines of matrix
1 view (last 30 days)
Show older comments
Hello. I do some research. I have some measured data - vector, And I have my own linear equations ( - each line of this matrix equation belongs to specific measurement and the point is that sometimes some measurement can not ve taken account) And I have the result- probable vector solved by the least square method. Probable vector is matrix 1x6. Linear equation is 6xn and measured data is 1xn. Minimum of n is 6 and maximum of n is 24. Because I dont know mathlab, I use excel...but some program in mathlab would help me with time. Each time I have to change size of matrixes in excel. And this is pissing me of :-) can you tell me how to do it in mathlab? Actually the first question would be: how many of measurements do you have? Or what is size of vector of measurement data? This changes the size of my linear equation. Maybe I found something like erase the line of matrix. But maybe you found the better way. Thank you for any opinion. Girl from Czechia saying hi😁
0 Comments
Answers (2)
Star Strider
on 21 Aug 2023
I am not certain what you want.
This calculates regressions on each column of ‘y’ and then plots it in the same colours as the original data —
x = (1:6).';
y = randn(6,8);
B = [x, ones(size(x))] \ y
figure
hold on
for k = 1:size(y,2)
hp = plot(x, y(:,k), 'o:');
hp.MarkerFaceColor = hp.Color;
rl = [x, ones(size(x))] * B(:,k);
plot(x, rl, '-', 'Color',hp.Color, 'LineWidth',1)
end
hold off
grid
xlabel('X')
ylabel('Y')
title('Linear Regressions')
B = [x.^2, x, ones(size(x))] \ y
figure
hold on
for k = 1:size(y,2)
hp = plot(x, y(:,k), 'o:');
hp.MarkerFaceColor = hp.Color;
rl = [x.^2, x, ones(size(x))] * B(:,k);
plot(x, rl, '-', 'Color',hp.Color, 'LineWidth',1)
end
hold off
grid
xlabel('X')
ylabel('Y')
title('Quadratic Regressions')
B = [x.^3, x.^2, x, ones(size(x))] \ y
figure
hold on
for k = 1:size(y,2)
hp = plot(x, y(:,k), 'o:');
hp.MarkerFaceColor = hp.Color;
rl = [x.^3, x.^2, x, ones(size(x))] * B(:,k);
plot(x, rl, '-', 'Color',hp.Color, 'LineWidth',1)
end
hold off
grid
xlabel('X')
ylabel('Y')
title('Third-Order Regressions')
.
4 Comments
Star Strider
on 21 Aug 2023
Not stupid at all.
I just fail to understand what you want to do from the description.
Bruno Luong
on 21 Aug 2023
Edited: Bruno Luong
on 21 Aug 2023
A = rand(24,6); % your full matrix
b = rand(24,1); % your measurements
% which data you want to remove?
removeidx = [1 4 24]; % removeidx = []; % to remove nothing
keep = setdiff(1:size(b,1), removeidx);
x = A(keep,:) \ b(keep,:)
That's all
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!