How to substitute x and y with X and Y respectively and get the same result as Test1(last line of my code)

1 view (last 30 days)
Below is my code. About the last line of my code, I would like to know how to substitute x and y with X and Y respectively and get the same result as Test1. Test1 is the output of "combine_wxx=vpa(combine_wxx)"
Thank you very much!!
clc
clear
format long
E=209e+3;
q=-1;
h=15;
D=6.459478021978022e+07;
I=2.8125e+02;
a=600;b=2400;
% change the value of mn
n =3;
[T1, T2] = meshgrid(1:2:n);
mn = [T1(:), T2(:)]
syms x y
x_value=0:100:600;
y_value=0:100:2400;
[X,Y]=meshgrid(x_value,y_value) ;
% Fine the amn
len=length(mn);
amn=zeros(1,len);
for i=1:len
m=mn(i,1);
n=mn(i,2);
amn(i)=(16*q/(m*n*D*pi^6))*(1/((m/a)^2+(n/b)^2)^2);
end
% Fine the wmn
for i=1:len
m=mn(i,1);
n=mn(i,2);
wmn(i)=amn(i).*((sin(m.*pi.*x./a)).*(sin(n.*pi.*y./b)));
wxx(i)=diff(wmn(i),x,2);
wyy(i)=diff(wmn(i),y,2);
end
combine_wxx=sum(wxx);
combine_wxx=vpa(combine_wxx)
% Test1 is the output of "combine_wxx=vpa(combine_wxx)" and I substitute x and y with X and Y respectively.
Test1=0.000010011120098275262104647981847237*sin(0.015707963267948966192313216916398.*X).*sin(0.0039269908169872415480783042290994.*Y) + 0.000033438807664284280352743957795044*sin(0.015707963267948966192313216916398.*X).*sin(0.0013089969389957471826927680763665.*Y) + 0.00012498683220294698455252916478176.*sin(0.0039269908169872415480783042290994.*Y).*sin(0.0052359877559829887307710723054658.*X) + 0.00081090072796029611652649055794769.*sin(0.0052359877559829887307710723054658.*X).*sin(0.0013089969389957471826927680763665.*Y)
% How should I use "subs" function or other function which you suggest to substitute x and y with X and Y respectively and get the same result as Test1
% I have tried "wxx_value=subs(combine_wxx,[x,y],[X,Y])" but it showed "Inconsistency between sizes of second and third arguments."

Answers (1)

Sambit Supriya Dash
Sambit Supriya Dash on 8 Jun 2021
Just before your major calculations (where you are willing to use the variables X & Y), you can add a line,
x = X; y = Y;
Then, whatever you write in terms of further calculations, you can use x & y as the replaced variables of X & Y.
  1 Comment
Mark
Mark on 8 Jun 2021
Edited: Mark on 8 Jun 2021
Thank you for your response.
But it seems the variables x and y do not transfer to X and Y.
I would like to transfer the variables X and Y from x and y for the the calculation of "combine_wxx=sum(wxx)". So I add the "x = X; y = Y;" And I got the combine_wxx =
0.000010011120098275262104647981847237*sin(0.015707963267948966192313216916398*x)*sin(0.0039269908169872415480783042290994*y) + 0.000033438807664284280352743957795044*sin(0.015707963267948966192313216916398*x)*sin(0.0013089969389957471826927680763665*y) + 0.00012498683220294698455252916478176*sin(0.0039269908169872415480783042290994*y)*sin(0.0052359877559829887307710723054658*x) + 0.00081090072796029611652649055794769*sin(0.0052359877559829887307710723054658*x)*sin(0.0013089969389957471826927680763665*y)
Also, the X and Y is 25 x 7 matrix, so the combine_wxx should also be 25 x 7 matrix.
Then I will try to use the funtion mesh(X,Y,combine_wxx) to plot the result.
Below is my code
clc
clear
format long
E=209e+3;
q=-1;
h=15;
D=6.459478021978022e+07;
I=2.8125e+02;
a=600;b=2400;
% change the value of mn
n =3;
[T1, T2] = meshgrid(1:2:n);
mn = [T1(:), T2(:)]
syms x y
x_value=0:100:600;
y_value=0:100:2400;
[X,Y]=meshgrid(x_value,y_value) ;
% Fine the amn
len=length(mn);
amn=zeros(1,len);
for i=1:len
m=mn(i,1);
n=mn(i,2);
amn(i)=(16*q/(m*n*D*pi^6))*(1/((m/a)^2+(n/b)^2)^2); % amn(i) storage the array
end
% Fine the wmn
for i=1:len
m=mn(i,1);
n=mn(i,2);
wmn(i)=amn(i).*((sin(m.*pi.*x./a)).*(sin(n.*pi.*y./b)));
wxx(i)=diff(wmn(i),x,2);
wyy(i)=diff(wmn(i),y,2);
end
x = X; y = Y;
combine_wxx=sum(wxx);
combine_wxx=vpa(combine_wxx)
% Test1 is the output of "combine_wxx=vpa(combine_wxx)" and I substitute x and y with X and Y respectively.
%Test1=0.000010011120098275262104647981847237*sin(0.015707963267948966192313216916398.*X).*sin(0.0039269908169872415480783042290994.*Y) + 0.000033438807664284280352743957795044*sin(0.015707963267948966192313216916398.*X).*sin(0.0013089969389957471826927680763665.*Y) + 0.00012498683220294698455252916478176.*sin(0.0039269908169872415480783042290994.*Y).*sin(0.0052359877559829887307710723054658.*X) + 0.00081090072796029611652649055794769.*sin(0.0052359877559829887307710723054658.*X).*sin(0.0013089969389957471826927680763665.*Y)
% How should I use "subs" function or other function which you suggest to substitute x and y with X and Y respectively and get the same result as Test1
% I have tried "wxx_value=subs(combine_wxx,[x,y],[X,Y])" but it showed "Inconsistency between sizes of second and third arguments."

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!