0% found this document useful (0 votes)
22 views3 pages

MATLAB Fourbar Master Code

Matlab Fourbar Code

Uploaded by

nmzondag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

MATLAB Fourbar Master Code

Matlab Fourbar Code

Uploaded by

nmzondag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

clc;

clear all;
close all;
tic
% Length of domain in X direction
LX = 1;
% Length of domain in Y direction
LY = 1;
% Number of Nodes along X
M = 51;
% Number of Nodes along Y
N = 51;
% X direction step size
DX = LX / (M - 1);
% Y direction step size
DY = LY / (N - 1);
% X and Y Coordinate system defined
X = 0 : DX : LX;
Y = 0 : DY : LY;
t_max = 5;
iter_max = 2000;
iter = 0;
error = 10;
tol = 1e-4;
U=zeros(M,N);
U_old=U;
U_new=U;
CFL1 = 0.4;
CFL2 = 0.6;
%CFL = 0.5;
c = 1;
%dt = CFL * DX / c;
t = 0;
%while (t < t_max)
% FUNCTIONS TO MAKE IT REBOUND:
% U(:,[1 end]) = 0;
% U([1 end],:) = 0;
while ( error > tol && iter < iter_max && t < t_max)
% CHANGE CFL FOR EACH
for ( CFL = CFL1 )
U(:,[1 end]) = 0;
U([1 end],:) = 0;
%CFL = 0.4;
dt = CFL * DX / c;
t = t + dt;
U_old = U;
U = U_new;
a = (M-1)/2;
b = (N-1)/2;
% NON ZERO FUNCTION
U(a,b)= dt^2 * 500 * sin((400 * pi * t) / 50);

for i = 2:M-1
for j = 2:N-1
U_new(i,j) = 2*U(i,j) - U_old(i,j) + CFL^2 *(U(i-1,j) + U(i,j-1) +
U(i+1,j) + U(i,j+1) - 4*U(i,j));
end
end

iter = iter + 1
error = max(max(abs(U_new - U)))
t = t+dt;
%ISOMETRIC VIEW
subplot(2,1,1);
mesh(X, Y, U'); colorbar; clim([-0.02 0.02])
title(sprintf('t (CFL = 0.4) = %.2f',t));
% Z AXIS LIMITS 0.1
axis([0 LX 0 LY -0.1 0.1]);
shg; pause(0.01);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
while ( CFL == CFL2)
U2=zeros(M,N);
U_old2=U2;
U_new2=U2;
%CFL = 0.6;
c = 1;
%dt = CFL * DX / c;

U2(:,[1 end]) = 0;
U2([1 end],:) = 0;
%CFL = 0.4;
dt2 = CFL * DX2 / c;
t = t + dt;
U_old2 = U2;
U2 = U_new2;
a = (M-1)/2;
b = (N-1)/2;
% NON ZERO FUNCTION
U2(a,b)= dt^2 * 500 * sin((400 * pi * t) / 50);

for i = 2:M-1
for j = 2:N-1
U_new2(i,j) = 2*U2(i,j) - U_old2(i,j) + CFL^2 *(U2(i-1,j) +
U2(i,j-1) + U2(i+1,j) + U2(i,j+1) - 4*U2(i,j));
end
end

iter = iter + 1
error = max(max(abs(U_new2 - U2)))
t = t + dt;
%ISOMETRIC VIEW
subplot(2,1,2);
mesh(X, Y, U2'); colorbar; clim([-0.02 0.02])
title(sprintf('t2 (CFL = 0.6) = %.2f',t));
% Z AXIS LIMITS 0.05
axis([0 LX 0 LY -0.1 0.1]);
shg; pause(0.01);
end
%}
end
clf;
subplot(2,1,1);
mesh(X, Y, U'); colorbar; clim([-0.02 0.02])
imagesc(X, Y, U'); colorbar; clim([-0.02 0.02])
title(sprintf('t = %.2f',t));
subplot(2,1,2);
mesh(X, Y, U2'); colorbar; clim([-0.02 0.02])
imagesc(X, Y, U2'); colorbar; clim([-0.02 0.02])
title(sprintf('t2 = %.2f',t));
toc
re

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy