Help me to finish my homework?

I have a matrix problem which is about calculating missing cells ! I created a code to find matrix U :
clc
deltax=0.5;
deltay=1;
x=0:deltax:1.5;
y=0:deltay:3;
k=0;
A=meshgrid(x,y);
U = sym('u%d%d', [4 4]);
eqna=@(x) x^2;
eqnb=@(x) (x-3)^2;
eqnc=@(y) y^2;
eqnd=@(y) (y-1.5)^2;
for i=x
k=k+1;
bcx1(k)=feval(eqna,i);
bcx2(k)=feval(eqnb,i);
end
clear i k
k=0;
for i=y
k=k+1;
bcy1(k)=feval(eqnc,i);
bcy2(k)=feval(eqnd,i);
end
clear i k
U(1,:)=bcx2;
U(4,:)=bcx1;
bcy1new=fliplr(bcy1);
U(:,1)=bcy1new;
bcy2new=fliplr(bcy2);
U(:,4)=bcy2new;
U
Here, I need to calculate u22,u23,u32,u33.I can do it manually with code below,But I need to do it with a loop like eqn(i)= ....U(i,j) .
u = sym('u%d%d', [2 4])
eqn1 = ((1-2*u(1,1)+u(2,1))/0.25)+(0.25-2*u(1,1)+u(1,2)) == 4;
eqn2 = ((u(2,2)-2*u(1,2)+4)/0.25)+(6.25-2*u(1,2)+u(1,1)) == 4;
eqn3 = ((0.25-2*u(2,1)+u(1,1))/0.25)+(u(2,2)-2*u(2,1)+1) == 4;
eqn4 = ((0.25-2*u(2,2)+u(1,2))/0.25)+(4-2*u(2,2)+u(2,1)) == 4;
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [u(1,1), u(1,2), u(2,1) ,u(2,2)])
Could you help me to do this in a loop ,Because I need this for much bigger matrixes.

Answers (0)

Tags

Asked:

on 20 Jan 2017

Edited:

on 20 Jan 2017

Community Treasure Hunt

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

Start Hunting!