PROGRAM Jacobi_methodIMPLICIT NONE! Declare VariablesReal, allocatable :: x(:),y(:),u(:,:), v(:,:),u_old(:,:)Real:: xy,h,Smax,tolerence,errorInteger:: i,j,JIPrint *, 'Enter the space size:'read*, xyPrint*, 'Enter the final space:'read*, Smaxh=Smax/xy !The size of spacestepPrint*, 'This gives stepsize of space h=',herror = 1.d0tolerence = 10E-4JI = 20 ! Total number of space stepsizeallocate (x(0:JI),y(0:JI),u(0:JI+1,0:JI+1),v(0:JI+1,0:JI+1),u_old(0:JI+1,0:JI+1))open(10,file='Jacobi_method.m')!Initial Conditionsx(0)= -1.0x(JI)= 1.0y(0)= -1.0y(JI)= 1.0do i=0,JIdo j=0,JIx(i)= -1 + i*h ! x-axixy(j)= -1 + j*h ! y-axisu(i,j)= 0 ! Entire Boundary is zeroend doend dowhile (error .GT. tolerence) do ! To stop do i=1, JI-1 do j=1,JI-1u_old(i,j)= u(i,j) ! To store the old values!Using 5-point scheme Formulae and rearranging the equationv(i,j)= 0.25*(u(i+1,j)+u(i,j+1)+u(i-1,j)+u(i,j-1)+h**2) end do end do do i=1, JI-1 do j=1, JI-1 u(i,j)= v(i,j) ! Giving the new values end do end doerror =0.d0 ! Now, error reading the value of zero do i=1,JI-1 do j=1, JI-1error = error + abs(u(i,j)- u_old(i,j)) ! To Stop end do end do end do!Print out the Approximate solution in matlab to get output and plot write(10,*) 'xyu =[' do i=0, JI do j=0,JIwrite(10,*) y(j),x(i),u(i,j) end do end dowrite(10,*) ']'write(10,*) " surf(xyu)" !Ploting diagram x,y,uwrite(10,*) "xlabel('x'),ylabel('y'),legend('Approximate Jacobi Scheme')"close(10) END PROGRAM Jacobi_method
Note: This is fortran code to generate output and plot the graphs in the matlab. There are no errors in fortran code and i can generate the outputs of u(i,j) between but -1<x<1 and -1<y<1 . I want to plot the graph of u(i,j) between -1<x<1 and -1<y<1 in the matlab but the plots is not properly working between -1 to 1 in both x-axis and y-axis.
To answer my question: you can look out the code after this (!Print out the Approximate solution in matlab to get output and plot) which is code for the matlab.
To make it clear, here is the output i want to plot generate by fortran code into matlab:
xyu =[ x-axis y-axis u(i,j)
-1.00000 -1.00000 0.00000
-0.900000 -1.00000 0.00000
-0.800000 -1.00000 0.00000
-0.700000 -1.00000 0.00000
-0.600000 -1.00000 0.00000
-0.500000 -1.00000 0.00000
-0.400000 -1.00000 0.00000
-0.300000 -1.00000 0.00000
-0.200000 -1.00000 0.00000
-9.999999E-02 -1.00000 0.00000
1.490116E-08 -1.00000 0.00000
0.100000 -1.00000 0.00000
0.200000 -1.00000 0.00000
0.300000 -1.00000 0.00000
0.400000 -1.00000 0.00000
0.500000 -1.00000 0.00000
0.600000 -1.00000 0.00000
0.700000 -1.00000 0.00000
0.800000 -1.00000 0.00000
0.900000 -1.00000 0.00000
1.00000 -1.00000 0.00000
-1.00000 -0.900000 0.00000
-0.900000 -0.900000 1.723304E-02
-0.800000 -0.900000 2.946638E-02
-0.700000 -0.900000 3.867569E-02
-0.600000 -0.900000 4.578741E-02
-0.500000 -0.900000 5.130390E-02
-0.400000 -0.900000 5.552766E-02
-0.300000 -0.900000 5.865262E-02
-0.200000 -0.900000 6.080576E-02
-9.999999E-02 -0.900000 6.206776E-02
1.490116E-08 -0.900000 6.248359E-02
0.100000 -0.900000 6.206776E-02
0.200000 -0.900000 6.080576E-02
0.300000 -0.900000 5.865262E-02
0.400000 -0.900000 5.552766E-02
0.500000 -0.900000 5.130390E-02
0.600000 -0.900000 4.578741E-02
0.700000 -0.900000 3.867569E-02
0.800000 -0.900000 2.946638E-02
0.900000 -0.900000 1.723304E-02
1.00000 -0.900000 0.00000
-1.00000 -0.800000 0.00000
-0.900000 -0.800000 2.946638E-02
-0.800000 -0.800000 5.195795E-02
-0.700000 -0.800000 6.945068E-02
-0.600000 -0.800000 8.317228E-02
-0.500000 -0.800000 9.390321E-02
-0.400000 -0.800000 0.102157
-0.300000 -0.800000 0.108280
-0.200000 -0.800000 0.112506
-9.999999E-02 -0.800000 0.114985
1.490116E-08 -0.800000 0.115803
0.100000 -0.800000 0.114985
0.200000 -0.800000 0.112506
0.300000 -0.800000 0.108280
0.400000 -0.800000 0.102157
0.500000 -0.800000 9.390321E-02
0.600000 -0.800000 8.317228E-02
0.700000 -0.800000 6.945068E-02
0.800000 -0.800000 5.195795E-02
0.900000 -0.800000 2.946638E-02
1.00000 -0.800000 0.00000
-1.00000 -0.700000 0.00000
-0.900000 -0.700000 3.867569E-02
-0.800000 -0.700000 6.945068E-02
-0.700000 -0.700000 9.400019E-02
-0.600000 -0.700000 0.113552
-0.500000 -0.700000 0.128985
-0.400000 -0.700000 0.140923
-0.300000 -0.700000 0.149812
-0.200000 -0.700000 0.155961
-9.999999E-02 -0.700000 0.159572
1.490116E-08 -0.700000 0.160764
0.100000 -0.700000 0.159572
0.200000 -0.700000 0.155961
0.300000 -0.700000 0.149812
0.400000 -0.700000 0.140923
0.500000 -0.700000 0.128985
0.600000 -0.700000 0.113552
0.700000 -0.700000 9.400019E-02
0.800000 -0.700000 6.945068E-02
0.900000 -0.700000 3.867569E-02
1.00000 -0.700000 0.00000
-1.00000 -0.600000 0.00000
-0.900000 -0.600000 4.578741E-02
-0.800000 -0.600000 8.317228E-02
-0.700000 -0.600000 0.113552
-0.600000 -0.600000 0.138058
-0.500000 -0.600000 0.157568
-0.400000 -0.600000 0.172748
-0.300000 -0.600000 0.184095
-0.200000 -0.600000 0.191962
-9.999999E-02 -0.600000 0.196590
1.490116E-08 -0.600000 0.198118
0.100000 -0.600000 0.196590
0.200000 -0.600000 0.191962
0.300000 -0.600000 0.184095
0.400000 -0.600000 0.172748
0.500000 -0.600000 0.157568
0.600000 -0.600000 0.138058
0.700000 -0.600000 0.113552
0.800000 -0.600000 8.317228E-02
0.900000 -0.600000 4.578741E-02
1.00000 -0.600000 0.00000
-1.00000 -0.500000 0.00000
-0.900000 -0.500000 5.130390E-02
-0.800000 -0.500000 9.390321E-02
-0.700000 -0.500000 0.128985
-0.600000 -0.500000 0.157568
-0.500000 -0.500000 0.180491
-0.400000 -0.500000 0.198419
-0.300000 -0.500000 0.211868
-0.200000 -0.500000 0.221216
-9.999999E-02 -0.500000 0.226723
1.490116E-08 -0.500000 0.228542
0.100000 -0.500000 0.226723
0.200000 -0.500000 0.221216
0.300000 -0.500000 0.211868
0.400000 -0.500000 0.198419
0.500000 -0.500000 0.180491
0.600000 -0.500000 0.157568
0.700000 -0.500000 0.128985
0.800000 -0.500000 9.390321E-02
0.900000 -0.500000 5.130390E-02
1.00000 -0.500000 0.00000
-1.00000 -0.400000 0.00000
-0.900000 -0.400000 5.552766E-02
-0.800000 -0.400000 0.102157
-0.700000 -0.400000 0.140923
-0.600000 -0.400000 0.172748
-0.500000 -0.400000 0.198419
-0.400000 -0.400000 0.218585
-0.300000 -0.400000 0.233757
-0.200000 -0.400000 0.244326
-9.999999E-02 -0.400000 0.250561
1.490116E-08 -0.400000 0.252622
0.100000 -0.400000 0.250561
0.200000 -0.400000 0.244326
0.300000 -0.400000 0.233757
0.400000 -0.400000 0.218585
0.500000 -0.400000 0.198419
0.600000 -0.400000 0.172748
0.700000 -0.400000 0.140923
0.800000 -0.400000 0.102157
0.900000 -0.400000 5.552766E-02
1.00000 -0.400000 0.00000
-1.00000 -0.300000 0.00000
-0.900000 -0.300000 5.865262E-02
-0.800000 -0.300000 0.108280
-0.700000 -0.300000 0.149812
-0.600000 -0.300000 0.184095
-0.500000 -0.300000 0.211868
-0.400000 -0.300000 0.233757
-0.300000 -0.300000 0.250269
-0.200000 -0.300000 0.261789
-9.999999E-02 -0.300000 0.268593
1.490116E-08 -0.300000 0.270843
0.100000 -0.300000 0.268593
0.200000 -0.300000 0.261789
0.300000 -0.300000 0.250269
0.400000 -0.300000 0.233757
0.500000 -0.300000 0.211868
0.600000 -0.300000 0.184095
0.700000 -0.300000 0.149812
0.800000 -0.300000 0.108280
0.900000 -0.300000 5.865262E-02
1.00000 -0.300000 0.00000
-1.00000 -0.200000 0.00000
-0.900000 -0.200000 6.080576E-02
-0.800000 -0.200000 0.112506
-0.700000 -0.200000 0.155961
-0.600000 -0.200000 0.191962
-0.500000 -0.200000 0.221216
-0.400000 -0.200000 0.244326
-0.300000 -0.200000 0.261789
-0.200000 -0.200000 0.273989
-9.999999E-02 -0.200000 0.281200
1.490116E-08 -0.200000 0.283586
0.100000 -0.200000 0.281200
0.200000 -0.200000 0.273989
0.300000 -0.200000 0.261789
0.400000 -0.200000 0.244326
0.500000 -0.200000 0.221216
0.600000 -0.200000 0.191962
0.700000 -0.200000 0.155961
0.800000 -0.200000 0.112506
0.900000 -0.200000 6.080576E-02
1.00000 -0.200000 0.00000
-1.00000 -9.999999E-02 0.00000
-0.900000 -9.999999E-02 6.206776E-02
-0.800000 -9.999999E-02 0.114985
-0.700000 -9.999999E-02 0.159572
-0.600000 -9.999999E-02 0.196590
-0.500000 -9.999999E-02 0.226723
-0.400000 -9.999999E-02 0.250561
-0.300000 -9.999999E-02 0.268593
-0.200000 -9.999999E-02 0.281200
-9.999999E-02 -9.999999E-02 0.288655
1.490116E-08 -9.999999E-02 0.291122
0.100000 -9.999999E-02 0.288655
0.200000 -9.999999E-02 0.281200
0.300000 -9.999999E-02 0.268593
0.400000 -9.999999E-02 0.250561
0.500000 -9.999999E-02 0.226723
0.600000 -9.999999E-02 0.196590
0.700000 -9.999999E-02 0.159572
0.800000 -9.999999E-02 0.114985
0.900000 -9.999999E-02 6.206776E-02
1.00000 -9.999999E-02 0.00000
-1.00000 1.490116E-08 0.00000
-0.900000 1.490116E-08 6.248359E-02
-0.800000 1.490116E-08 0.115803
-0.700000 1.490116E-08 0.160764
-0.600000 1.490116E-08 0.198118
-0.500000 1.490116E-08 0.228542
-0.400000 1.490116E-08 0.252622
-0.300000 1.490116E-08 0.270843
-0.200000 1.490116E-08 0.283586
-9.999999E-02 1.490116E-08 0.291122
1.490116E-08 1.490116E-08 0.293616
0.100000 1.490116E-08 0.291122
0.200000 1.490116E-08 0.283586
0.300000 1.490116E-08 0.270843
0.400000 1.490116E-08 0.252622
0.500000 1.490116E-08 0.228542
0.600000 1.490116E-08 0.198118
0.700000 1.490116E-08 0.160764
0.800000 1.490116E-08 0.115803
0.900000 1.490116E-08 6.248359E-02
1.00000 1.490116E-08 0.00000
-1.00000 0.100000 0.00000
-0.900000 0.100000 6.206776E-02
-0.800000 0.100000 0.114985
-0.700000 0.100000 0.159572
-0.600000 0.100000 0.196590
-0.500000 0.100000 0.226723
-0.400000 0.100000 0.250561
-0.300000 0.100000 0.268593
-0.200000 0.100000 0.281200
-9.999999E-02 0.100000 0.288655
1.490116E-08 0.100000 0.291122
0.100000 0.100000 0.288655
0.200000 0.100000 0.281200
0.300000 0.100000 0.268593
0.400000 0.100000 0.250561
0.500000 0.100000 0.226723
0.600000 0.100000 0.196590
0.700000 0.100000 0.159572
0.800000 0.100000 0.114985
0.900000 0.100000 6.206776E-02
1.00000 0.100000 0.00000
-1.00000 0.200000 0.00000
-0.900000 0.200000 6.080576E-02
-0.800000 0.200000 0.112506
-0.700000 0.200000 0.155961
-0.600000 0.200000 0.191962
-0.500000 0.200000 0.221216
-0.400000 0.200000 0.244326
-0.300000 0.200000 0.261789
-0.200000 0.200000 0.273989
-9.999999E-02 0.200000 0.281200
1.490116E-08 0.200000 0.283586
0.100000 0.200000 0.281200
0.200000 0.200000 0.273989
0.300000 0.200000 0.261789
0.400000 0.200000 0.244326
0.500000 0.200000 0.221216
0.600000 0.200000 0.191962
0.700000 0.200000 0.155961
0.800000 0.200000 0.112506
0.900000 0.200000 6.080576E-02
1.00000 0.200000 0.00000
-1.00000 0.300000 0.00000
-0.900000 0.300000 5.865262E-02
-0.800000 0.300000 0.108280
-0.700000 0.300000 0.149812
-0.600000 0.300000 0.184095
Related Question
- After giving row and column names to a matrix, how to access the particular elements in the matrix using the (rowname, column name)
- How do you convert numbers to percentages
- How to resolve CAT arguments dimensions, which are not consistent, when using cell2mat command
- Does the loop not work for the increment stated
- How to make a permanent change to a matrix using sortrows
- How to replace a column with an incremented vector starting at -10
- How to reverse the direction of the rows and columns using printmat
Best Answer