divide and conquer
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
please
anyone can give me source code about divide and conquer method
thank you
2 Commenti
Oleg Komarov
il 25 Mar 2012
Being "an algorithm design paradigm" there's no specific source code for it: http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm
Also, additional info could give contributors a chance of answering:
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Risposte (2)
Walter Roberson
il 25 Mar 2012
Certainly. In order for this to be a proper "divide and conquer" source contribution, each of the readers of this site will contribute part of the source, and it will be up to you to put everything together.
My contribution to your D&Q source follows on the next line:
=
Hope that helps!
4 Commenti
Walter Roberson
il 22 Mag 2017
Peter Weigel comments to Walter Roberson:
This comment is detrimental to the health of the MathWorks forums.
Walter Roberson
il 22 Mag 2017
Peter Weigel: the MathWorks forums seem to have thrived in the five years since I posted that response to someone who asked a vague question and expected to be given full source without any effort on their part.
RAJESH
il 29 Ago 2024 alle 7:59
clc; clear all; close all;
% Initialization
iter = 1;
x = [0 0.25 0.5 0.75 1];
y = [5 6 3 2 8];
% Prepare X1 and Y1 matrices
X1 = zeros(4,4);
x1 = [x(3) x(4) x(5)];
x2 = [x(3) x(4) x(5)];
x3 = [x(1) x(2) x(3)];
x4 = [x(1) x(2) x(3) x(4)];
r = [length(x1) length(x2) length(x3) length(x4)];
X1(1,1:r(1)) = x1;
X1(2,1:r(2)) = x2;
X1(3,1:r(3)) = x3;
X1(4,1:r(4)) = x4;
Y1 = zeros(4,4);
y1 = [y(3) y(4) y(5)];
y2 = [y(3) y(4) y(5)];
y3 = [y(1) y(2) y(3)];
y4 = [y(1) y(2) y(3) y(4)];
r = [length(y1) length(y2) length(y3) length(y4)];
Y1(1,1:r(1)) = y1;
Y1(2,1:r(2)) = y2;
Y1(3,1:r(3)) = y3;
Y1(4,1:r(4)) = y4;
alpha = [-0.8 0.7 0.7 -0.8];
N = length(x);
% Initialize d and d1
d = zeros(1, N-1); % Adjust the size as needed
d1 = zeros(4, 4); % Adjust the size as needed
% Computation of a, b, and q values
for i = 1:N-1
a(i) = (x(i+1) - x(i)) / (X1(i, r(i)) - X1(i, 1));
b(i) = (X1(i, r(i)) * x(i) - X1(i, 1) * x(i+1)) / (X1(i, r(i)) - X1(i, 1));
% Calculating q(i) with careful attention to parentheses
term1 = (y(i) - alpha(i) * Y1(i, 1)) * (1 - (x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1))).^3;
term2 = (y(i+1) - alpha(i) * Y1(i, r(i))) * ((x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1))).^3;
term3 = (r(i) * (y(i) - alpha(i) * Y1(i, 1)) + (x(i+1) - x(i)) * d(i) - alpha(i) * d1(i, 1) * (X1(i, r(i)) - X1(i, 1))) * ...
(1 - (x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1))).^2 * (x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1));
term4 = (r(i) * (y(i+1) - alpha(i) * Y1(i, r(i))) - (x(i+1) - x(i)) * d(i+1) + alpha(i) * d1(i, r(i)) * (x1(i, r(i)) - x1(i, 1))) * ...
(1 - (x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1))) * ((x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1))).^2;
numerator = term1 + term2 + term3 + term4;
denominator = 1 + (r(i) - 3) * (1 - (x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1))) * ((x(i) - X1(i, 1)) / (X1(i, r(i)) - X1(i, 1)));
q(i) = numerator / denominator;
end
abq_values = [a' b' q'];
L = []; L1 = []; X = []; Y = [];
p = N;
for k = 1:iter
fprintf("ITERATION=%d\n", k)
for i = 1:N-1
for j = 1:p-2
if(k == 1) % First iteration
% Input data is (x,y) or given data
L(i,j) = a(i) * X(i,j) + b(i);
L1(i,j) = alpha(i) * Y1(i,j) + (q(i) * X1(i,j));
else % More than one iteration
% Input data is (X1, Y1) OR output after the first iteration
L(i,j) = a(i) * X(i,j) + b(i);
L1(i,j) = alpha(i) * Y(i,j) + (q(i) * X1(i,j));
end
end
X = [X L(i,:)];
Y = [Y L1(i,:)];
end
X1 = X;
Y1 = Y;
X = [];
Y = [];
g = [X1' Y1'];
g = str2num(num2str(g,10));
g = unique(g, 'rows');
X1 = g(:, 1);
Y1 = g(:, 2);
p = length(X1);
end
plot(x, y, '.k', 'markersize', 80);
hold on;
plot(X1, Y1, 'b-');
Index exceeds the number of array elements. Index must not exceed 4. Please give me correct program
0 Commenti
Vedere anche
Categorie
Scopri di più su Data Import and Export 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!