Borrar filtros
Borrar filtros

how to plot 3-d using surf(xyu) where -1<x1, -1<y<1.

4 visualizaciones (últimos 30 días)
dave
dave el 24 de Feb. de 2014
Comentada: dave el 25 de Feb. de 2014
PROGRAM Jacobi_method
IMPLICIT NONE
! Declare Variables
Real, allocatable :: x(:),y(:),u(:,:), v(:,:),u_old(:,:)
Real:: xy,h,Smax,tolerence,error
Integer:: i,j,JI
Print *, 'Enter the space size:'
read*, xy
Print*, 'Enter the final space:'
read*, Smax
h=Smax/xy !The size of spacestep
Print*, 'This gives stepsize of space h=',h
error = 1.d0
tolerence = 10E-4
JI = 20 ! Total number of space stepsize
allocate (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 Conditions
x(0)= -1.0
x(JI)= 1.0
y(0)= -1.0
y(JI)= 1.0
do i=0,JI
do j=0,JI
x(i)= -1 + i*h ! x-axix
y(j)= -1 + j*h ! y-axis
u(i,j)= 0 ! Entire Boundary is zero
end do
end do
while (error .GT. tolerence) do ! To stop
do i=1, JI-1
do j=1,JI-1
u_old(i,j)= u(i,j) ! To store the old values
!Using 5-point scheme Formulae and rearranging the equation
v(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 do
error =0.d0 ! Now, error reading the value of zero
do i=1,JI-1
do j=1, JI-1
error = 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,JI
write(10,*) y(j),x(i),u(i,j)
end do
end do
write(10,*) ']'
write(10,*) " surf(xyu)" !Ploting diagram x,y,u
write(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
-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.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.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.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.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.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.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 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
]

Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Feb. de 2014
It is easier not to generate xyu like that. Instead, output x, then output y, then output u. Then on the MATLAB side,
surf(x, y, reshape(u, length(x), length(y)) )
For this to work properly, when you output u, output it down the columns rather than across the rows. Or output it in matrix form with multiple columns per line.
  1 comentario
dave
dave el 25 de Feb. de 2014
Thank you very much. I have used contour(x, y, reshape(u, length(x), length(y)) ) and the graph is coming even better.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by