Newbie question using solve

Hi, I am really a newbie in using matlab and have a problem solving a mathematical model. How can I make this work in MATLAB?
Bi = 0.43;
t = -16.9;
N = x/(2*Bi)+ t/2;
y = 2*(1-coth(x))*(cosh(x)-cosh(N)) + ...
x/((2*Bi)*exp(-N))+(1-coth(x)/(2*Bi))*x*sinh(x);
P = solve(y);
M = P/(2*Bi)+t/2;
C = (P^2/sinh(P)^2)*exp(-M)*(cosh(P)-cosh(M));
??? Error using ==> map>checkstat at 29
Error: argument must be of 'Type::Arithmetical' [sinh]
Error in ==> map at 15
checkstat(result,status,nargout);
Error in ==> sym.sinh at 9
Y = map(X,'sinh');
Thanks in advance

댓글 수: 5

Andrew Newell
Andrew Newell 2011년 4월 7일
Hi, newbie. Can you please edit your question (click on "edit") and format your code so it is readable? Put just one command on each line and indent by two spaces (so the code looks grey in the preview window).
Matt Tearle
Matt Tearle 2011년 4월 7일
What is x? Is it symbolic or numeric? Or perhaps a better question: what are you actually trying to do? Solve y for what?
benjamin
benjamin 2011년 4월 7일
X is a variable. I am trying to find the value of C. For this I have to solve the equation y to x so I can fill in P into M and M into C. But I got an error.
Thx
Matt Tearle
Matt Tearle 2011년 4월 7일
Yes, I got that much from the code. What I'm trying to understand is your intent. What does "solve the equation y to x" mean? Are you trying to solve y(x) = 0 for x, or *invert* the expression y(x) (to get x(y))? The solve function will find x such that y = 0, then P will be that x value. Assuming that's what you want, if I add "syms x" at the beginning, your code works fine. So what is x, how is it created? Can you do "whos x" and report the result.
benjamin
benjamin 2011년 4월 7일
>> whos x
Name Size Bytes Class Attributes
x 1x1 126 sym
I also did syms x at the beginning of my code and i keep getting this error. The point is to get a valuae for C, and to do so I have to find the roots (zero's) of the equation y.

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

답변 (2개)

Walter Roberson
Walter Roberson 2011년 4월 7일

0 개 추천

y is highly unstable numerically. You would have to push the symbolic toolbox to somewhere past 50 decimal places to find the zero between 35.571688344555791899140414695 and 35.571688344555791899140414696 (there is a difference of approximately 10^92 between those two points.)
The root near 2.5451437638625637590284940922858247397328944979967 is easy to find, but any other roots are not. I have not been able to determine whether there are additional roots.
benjamin
benjamin 2011년 4월 9일

0 개 추천

But can anyone help me with the error i get? If i can solve C with just one root, I am allready very happy! Thanks

댓글 수: 4

Walter Roberson
Walter Roberson 2011년 4월 9일
Are you looking for a numeric solution or an algebraic solution? If you are looking for a numeric solution then use matlabFunction to convert y to a MATLAB function from a symbolic function, and then use fzero() on the result.
benjamin
benjamin 2011년 4월 12일
yes, I need the numerical solution of C. I tried your method but I still can't make it work :( Can you give me the code please,I would be of great help!!
syms x
Bi = 0.43;
t = -16.9;
N = x/(2*Bi)+ t/2;
y = 2*(1-coth(x))*(cosh(x)-cosh(N))+x/((2*Bi)*exp(-N))+(1-coth(x)/(2*Bi))*x*sinh(x);
P = solve(y);
M = P/(2*Bi)+t/2;
C = (P^2/sinh(P)^2)*exp(-M)*(cosh(P)-cosh(M));
Walter Roberson
Walter Roberson 2011년 4월 12일
YM = matlabFunction(y);
P = fzero(YM,3); %3 is the initial guess
Be warned, though, that the function is highly unstable numerically, and that you may have trouble determining a useful solution in double precision.
benjamin
benjamin 2011년 4월 12일
Thank you very much Walter!!!!!

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

카테고리

질문:

2011년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by