Compute function of two variables

2 ビュー (過去 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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by