Very simple simultaneous eqs.

조회 수: 1 (최근 30일)
jnaumann
jnaumann 2011년 8월 8일
I am working on a script to pinpoint acoustic sources from differences in arrival times. This is a very basic question but I'm new to Matlab so hopefully the answer will be very simple. This is what I have done so far.
function timediff
eq1 = '((D1^2-(t1^2)*(c^2))/(t1*c+D1*cos(y-theta1))*0.5)-x';
eq2 = '((D2^2-(t2^2)*(c^2))/(t2*c+D2*cos(theta3-y))*0.5)-x';
s=solve(eq1,eq2)
D1 = input('Enter value of D1: ');
D2 = input('Enter value of D2: ');
c = input('Enter value of speed of sound (c): ');
theta1 = input('Enter value of theta1: ');
theta3 = input('Enter value of theta3: ');
t1 = input('Enter value of time difference 1: ');
t2 = input('Enter value of time difference 2: ');
a=vpa(s.x)
b=vpa(s.y)
plot(a,b,'x')
When I run this and enter the paramaters it calculates a and b but doesn't evaluate them numerically - how do I do this because I would like to be able to plot them on a graph.
Many thanks in advance

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 8월 8일
doc subs %substitute numerical values
doc double %convert symbolic to double precision
  댓글 수: 2
jnaumann
jnaumann 2011년 8월 8일
I tried using the double command and the following error message was produced;
??? Error using ==> mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Error in ==> sym.sym>sym.double at 936
Xstr = mupadmex('symobj::double', S.s, 0);
Error in ==> timediff at 12
a=double(s.x)
If I use the vpa command as suggested I still don't get the amsers in the numerical format.
Also how would i use the subs command because I have already entered the numerical values for the parameters?
Sean de Wolski
Sean de Wolski 2011년 8월 8일
Use SUBS to substitute your values for D1 D2 c et al. into the s.x,s.y symbolics.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by