필터 지우기
필터 지우기

Compute function of two variables

조회 수: 1 (최근 30일)
Justin Bruh
Justin Bruh 2017년 1월 28일
답변: Justin Bruh 2017년 1월 28일
I have a function Ux=f(x,t) where f(x,t) is an infinite sine series (which I've truncated at 50 terms). I want to find the values of Ux at every x and t and out put it as a matrix (# of x values X #of t values), then plot a contour of where Ux is zero on a 2-D plot of x vs t (I want t on the y-axis). Here's what I've tried so far:
syms x t
%Establish An Coefficients
n=0;
for m=1:1:50
n=n+1;
if n==2
A(n)=0.5;
else
A(n)=(-4*sin(.5*pi*m))/((pi*m^2)-(4*pi));
end
end
%Determine T(t) Values for each Value of An
index=0;
for n=1:1:50
index=index+1;
T(index)=exp(-(n^2)*(pi^2)*t);
end
%Find values of X'(x)
index=0;
for n=1:1:50
index=index+1;
dX(index)=(A(n))*(n*pi)*cos(n*pi*x);
end
Ux=(sum(dX.*T));
x=.2:.01:.75;
t=0:.005:.5;
Flux=eval(Ux);
[A,B] = meshgrid(x,t);
v=[0,0];
figure
contour(A,B,Flux,v)
so x is 1 X 56 matrix and t is a 1 X 101 matrix. My understanding is that to make the contour part work I need 'Flux' to output as a 56 X 101 matrix. I keep getting the following error:
Error in sym/eval (line 11)
s = evalin('caller',vectorize(map2mat(char(x))));
Error in zeroflux (line 42)
Flux=eval(Ux);
  댓글 수: 2
Jan
Jan 2017년 1월 28일
Is this the complete error message? It tells only, where the problem occurres, but not, what the problem is.
Justin Bruh
Justin Bruh 2017년 1월 28일
That is the complete error message

댓글을 달려면 로그인하십시오.

답변 (1개)

Justin Bruh
Justin Bruh 2017년 1월 28일
I've figured it out. Everything down to the end of the 3 loops is the same. Then I added this fourth loop:
index1=0;
index2=0;
for t=0:.005:1
index1=1+index1;
index2=0;
for x=0:0.01:1
index2=index2+1;
Ux(index1,index2)=eval(sum(dX.*T));
end
end
x=0:.01:1;
t=0:.005:1;
[A,B] = meshgrid(x,t);
v=[0,0];
figure
contour(A,B,Ux,v)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by