Operator '*' is not supported for operands of type 'function_handle'.
Mostra commenti meno recenti
draw_my_plots
function draw_my_plots
L = 3;
eta_0 = 1 % Initial value of eta
tol = 1e-5;
rho = 1;
max_iter = 100; % Maximum number of iterations
n = 1:max_iter;
eta_n = eta_0;
eta_(n+1) = (eta_n) + 1;
delta_eta = [];
% Define the function Psi as a separate MATLAB function
function y = Psi(eta);
y = rho/2; % Implementation of the contraction mapping with coefficient rho = 1
end
% Step 2: Implement the iteration loop
while n <= max_iter
omega_n = 1 ./ (n .* (n + 1));
zeta_n = 1 ./ (n + 1);
vartheta_n = 1 ./ (n + 1);
A = @(eta) L * eta(n) ;
J = @(eta) eta(n);
eta_(n+1) = vartheta_n * Psi((eta_n + eta_(n+1)) / 2) + zeta_n * (eye(size(A)) - omega_n * A * J) * ((eta_n + eta_(n+1)) / 2);
if norm(eta_(n+1) - eta_n) < tol
break;
end
delta_eta = [delta_eta, norm(eta_(n+1) - eta_n)];
eta_n = eta_(n+1);
n = n + 1;
end
% Step 4: Plot the convergence rate
figure;
plot(1:length(delta_eta), delta_eta);
xlabel('Iteration number');
ylabel('||eta_{n+1} - eta_n||');
% Step 5: Generate the table of number of iterations
n_vec = 1:iter;
eta_vec = [eta_0, eta_n];
table_data = [iter_vec' n_vec'];
% Step 6: Display the table and plot
disp('Table of number of iterations:');
disp(table_data);
% Plot the convergence rate graph
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Installing Products in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!