Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

% Plotting The Given Question With Coordinates

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

clc,clear

% Plotting the given question with coordinates


s=[0;0];
s1x=[-15 -50];
s1y=[-30 75];
s1=[s1x;s1y];
s2x=[20 100 100 20];
s2y=[18 18 78 78 ];
s2=[s2x;s2y];
s3=[0;60];
figure(1)
plot(s(1),s(2),'ok','linewidth',1), hold on;
plot(s1x,s1y,'k','linewidth',1), hold on;
axis([-100 150 -100 150]);
rectangle('Position',[20 18 80 60],'linewidth',1);
hold on;
title('SOURCE REPRESENTATION','Fontsize',16)
plot(s3(1),s3(2),'*k','linewidth',1);
hold on
txt1='Mmax=7.3',txt2='SOURCE 1',txt3 ='log \lambdam = 4.4-1.0M'
txt4='SOURCE 2',txt5='Mmax=7.7',txt6 ='log \lambdam = 3.5-0.8M'
txt7='SOURCE 3',txt8='Mmax=5',txt9 ='log \lambdam = 2.7-1.2M'
txt10='Site',txt11='(-50,75)',txt12='(-15,-30)',txt13='(0,60)'
txt14='(0,0)',txt15='(20,18)',txt16='(100,18)',txt17='(20,78)',txt18='(100,7
8)'
text(-65,50,txt2),text(-65,40,txt1),text(-65,30,txt3),text(50,60,txt4),hold
on
text(50,50,txt5),text(50,40,txt6),text(-10,90,txt7),text(-10,80,txt8),hold on
text(-10,70,txt9),text(0,5,txt10),hold on
text(-55,80,txt11),text(-20,-35,txt12),text(0,55,txt13),text(0,-5,txt14),hold
on
text(15,12,txt15),text(95,12,txt16),text(15,85,txt17),text(95,85,txt18)
hold off
STEP 1: Source to site distance

%source 1: Linear source;


b1=norm([(diff(s1x)) (diff(s1y))]);
area=norm(cross([diff(s1x) diff(s1y) 0],[s1x(2)-s(1),s1y(2)-s(2),0]))/2;
s1_short=2*area/ b1;
s1_long = max(norm([s1x(2)-s(1),s1y(2)-s(2)]),norm([s1x(1)-s(1),s1y(1)-
s(2)]))
s1b = min(norm([s1x(2)-s(1),s1y(2)-s(2)]),norm([s1x(1)-s(1),s1y(1)-
s(2)]))

%source 2: Areal source;


s21=norm([s2x(1)-s(1) s2y(1)-s(2)]);
s22=norm([s2x(2)-s(1) s2y(2)-s(2)]);
s23=norm([s2x(3)-s(1) s2y(3)-s(2)]);
s24=norm([s2x(4)-s(1) s2y(4)-s(2)]);
s2_short=min([s21,s22,s23,s24]);
s2_long=max([s21,s22,s23,s24]);

%source 3: point source;


s3_dis=norm([s3(2)-s(2),s3(1)-s(1)]);

%Displaying tabulated site source distance

SOURCE={'SOURCE 1';'SOURCE 2';'SOURCE 3'};


a=[4.4;3.5;2.7]; % Guttenberg-Richter 'a' value
b=[1;0.8;1.2]; % Guttenberg-Richter 'b' value
Magnitude=[7.3;7.7;5]; %Magnitude of each source
Shortest_Distance=[s1_short;s2_short;s3_dis];
Longest_Distance=[s1_long;s2_long;s3_dis];
T=table(SOURCE,a,b,Magnitude,Shortest_Distance,Longest_Distance);
display(T); % Table showing the datas for the sources
display('Where a and b= Guttenberg-Richter a and b value');
display('Distances are in km');
DISTRIBUTION OF SOURCE TO SITE DISTANCE

%SOURCE 1;
range1=s1_long-s1_short;
div1=range1/10;
for i1=0:10;
distance1(i1+1)=s1_short+div1*i1;
end

for j1=1:10;
avg_value(j1)=(distance1(j1)+distance1(j1+1))/2
end

%calculation probabilty;
for i=2:length(distance1)
a(i-1)=sqrt(distance1(i)^2-distance1(1)^2)
end
pa(1)=2*a(1)/110.64;
s1a=s1_long;
s1x=sqrt(s1b^2-s1_short^2);
pa(2)=(a(2)+s1x)/b1;
for i=1:(length(distance1)-3);
pa(i+2)=(a(i+2)+s1x)/b1
end
prob1=[pa(1),diff(pa)];

%PROBABILTY IN TABULAR FORM:


Distance=avg_value'
Probability=prob1'
Table1=table(Distance,Probability);
clear Distance Probability;

%SOURCE 2;
range2=s2_long-s2_short;
div2=range2/10;
for i2=0:10;
distance2(i2+1)=s2_short+div2*i2;
end
for j1=1:10;
avg_value2(j1)=(distance2(j1)+distance2(j1+1))/2
end

%diving source into 50x50 elements


rect=[(s2x(2)-s2x(1));(s2y(3)-s2y(1))]
rect_small=rect/50;
c_x(1)=s2x(1)+rect_small(1)/2;
c_y(1)=s2y(1)+rect_small(2)/2;
for i=1:49
c_x(i+1)=c_x(i)+rect_small(1);
c_y(i+1)=c_y(i)+rect_small(2);
end

%finding the distance of midpoint from souce to midpoint of each element


for i=1:50;
for j=1:50;
c_r(i,j)=sqrt(c_y(i)^2+c_x(j)^2);
end
end

%no of points lying between two distances;


count=zeros(1,11);
for i=1:50
for j=1:50
for k=1:11
if c_r(i,j)<distance2(k)
for l=k:11
count(l)=count(l)+1;
disp(count)
end
break
end
end
end
end
count=count(2:end);

prob2=count/2500;
prob2=[prob2(1),diff(prob2)];

Distance=distance2(2:11)'
No_of_points_lying_within=count';
No_of_points_lying_between=[count(1),diff(count)]';
for i=1:(length(distance2)-1)
Midpoint_distance(i)=((distance2(i)+distance2(i+1))/2);
end
Midpoint_distance=Midpoint_distance';
Probability=prob2';

Table2=table(Distance,No_of_points_lying_within,No_of_points_lying_betwee
n,Midpoint_distance,Probability)
clear Probablity;

%SOURCE 3;
prob3=1

%barchart

figure(2)
subplot(131);
bar(avg_value,prob1);
xlabel('Distance(km)');
ylabel('P[R=r]');
hold on;
subplot(132);
bar(Midpoint_distance,prob2);
xlabel('Distance(km)');
ylabel('P[R=r]');
hold on;
subplot(133);
bar(60,prob3,10);
axis([0 100 0 2])
xlabel('Distance(km)');
ylabel('P[R=r]');
hold off;
a = axes;
t1 = title('Source to Site probability distribution for source 1,2 and 3');
a.Visible = 'off'; % set(a,'Visible','off');
t1.Visible = 'on'; % set(t1,'Visible','on');
hold off
STEP 2: TEMPORAL UNCERNTAINITY;

lamda_m1=10^(4.4-1*4);
lamda_m2=10^(3.5-0.8*4);
lamda_m3=10^(2.7-1.2*4);
lamda_m=lamda_m1+lamda_m2+lamda_m3;

%source1
mo1=4;
m_max1=7.3;
m_div1=(m_max1-mo1)/10;
for i=0:10;
m_int1(i+1)=mo1+i*m_div1;
end

for i=1:(length(m_int1)-1);
m_avg1(i)=(m_int1(i)+m_int1(i+1))/2
end

for i=1:(length(m_int1)-1)
p_m1(i)=2.303*b(1)*(exp(-2.303*b(1)*(m_avg1(i)-mo1)))/(1-exp(-
2.303*b(1)*(m_max1-mo1)))*(m_int1(i+1)-m_int1(i));
end

Magnitude=m_avg1';
Probability=p_m1';
Table_3=table(Magnitude,Probability)
clear Magnitude Probability

%source2
mo2=4;
m_max2=7.7;
m_div2=(m_max2-mo2)/10;
for i=0:10;
m_int2(i+1)=mo2+i*m_div2;
end

for i=1:(length(m_int2)-1);
m_avg2(i)=(m_int2(i)+m_int2(i+1))/2
end

for i=1:(length(m_int2)-1)
p_m2(i)=2.303*b(2)*(exp(-2.303*b(2)*(m_avg2(i)-mo2)))/(1-exp(-
2.303*b(2)*(m_max2-mo2)))*(m_int2(i+1)-m_int2(i));
end

Magnitude=m_avg2';
Probability=p_m2';
Table_4=table(Magnitude,Probability)
clear Magnitude Probability

%source3
mo3=4;
m_max3=5;
m_div3=(m_max3-mo3)/10;
for i=0:10;
m_int3(i+1)=mo3+i*m_div3;
end

for i=1:(length(m_int3)-1);
m_avg3(i)=(m_int3(i)+m_int3(i+1))/2
end

for i=1:(length(m_int3)-1)
p_m3(i)=2.303*b(3)*(exp(-2.303*b(3)*(m_avg3(i)-mo3)))/(1-exp(-
2.303*b(3)*(m_max3-mo3)))*(m_int3(i+1)-m_int3(i));
end

Magnitude=m_avg3';
Probability=p_m3';
Table_5=table(Magnitude,Probability);
clear Magnitude Probability

%barchart
figure(3)
subplot(131);
bar(m_avg1,p_m1);
xlabel('Magnitude');
ylabel('P[M=m]');
hold on;
subplot(132);
bar(m_avg2,p_m2);
xlabel('Magnitude');
ylabel('P[M=m]');
hold on;
subplot(133);
bar(m_avg3,p_m3);
xlabel('Magnitude');
ylabel('P[M=m]');
hold on;
a2 = axes;
t2 = title('Magnitude probability distribution for source 1,2 and 3');
a2.Visible = 'off'; % set(a,'Visible','off');
t2.Visible = 'on'; % set(t1,'Visible','on');

STEP 4

s_lny=0.57; %uncertainity of standard deviation

%SOURCE 1
a_star=0.01:0.01:1;
z=zeros(10,10);
P_m_r1=zeros(10,10);
ln_pha=zeros(10,10);
n=length(a_star);
m=cell(n,1);
l=cell(n,1);
for i=1:n;
for j=1:length(m_avg1);
for k=1:length(avg_value);
ln_pha(j,k)=6.74+0.859*m_avg1(j)-1.80*log(avg_value(k)+25);
end
end

for j=1:length(m_avg1);
for k=1:length(avg_value);
z(j,k)=(log(a_star(i)*981)-ln_pha(j,k))/s_lny;
P_m_r1(j,k)=((1-normcdf(z(j,k)))*p_m1(j)*prob1(k));
end
end
m{i}=(P_m_r1);
l{i}=(P_m_r1*lamda_m1);
end
prob1_final=zeros(1,100);
for i=1:100;
prob1_final(i)=(sum(sum(l{i})));
end

%SOURCE 2
a_star=0.01:0.01:1;
z2=zeros(10,10);
P_m_r2=zeros(10,10);
ln_pha2=zeros(10,10);
n2=length(a_star);
m2=cell(n2,1);
l2=cell(n2,1);
for i=1:n2;
for j=1:length(m_avg2);
for k=1:length(avg_value2);
ln_pha2(j,k)=6.74+0.859*m_avg2(j)-1.80*log(avg_value2(k)+25);
end
end

for j=1:length(m_avg2);
for k=1:length(avg_value2);
z2(j,k)=(log(a_star(i)*981)-ln_pha2(j,k))/s_lny;
P_m_r2(j,k)=((1-normcdf(z2(j,k)))*p_m2(j)*prob2(k));
end
end
m2{i}=(P_m_r2);
l2{i}=(P_m_r2*lamda_m2);
end
prob2_final=zeros(1,100);

for i=1:100;
prob2_final(i)=(sum(sum(l2{i})));
end

%SOURCE 3
a_star=0.01:0.01:1;
z3=zeros(100,10);
P_m_r3=zeros(100,10);
ln_pha3=zeros(100,10);
for i=1:length(a_star);
for j=1:length(m_avg3);
ln_pha3(i,j)=6.74+0.859*m_avg3(j)-1.80*log(s3_dis+25);
z3(i,j)=(log(a_star(i)*981)-ln_pha3(i,j))/s_lny;
P_m_r3(i,j)=((1-normcdf(z3(i,j)))*p_m3(j)*prob3);
end
end

prob3_final=sum(P_m_r3,2)';
p_all=zeros(100,1)
p_all=prob1_final'+prob2_final'+prob3_final';

%plotting final results


figure(4)
semilogy(a_star,prob1_final);
grid on, hold on
semilogy(a_star,prob2_final);
hold on
semilogy(a_star,prob3_final);
hold on
semilogy(a_star,p_all,'-k');
legend('Source 1', 'Source 2', 'Source 3','All');
title('Seismic Hazard Curve');
xlabel('PHA(g)');
ylabel('Mean annual rate of Exceedence of PHA');

You might also like