MATLAB Answers

what is wrong in this code

조회 수: 27(최근 30일)
Angad Singh Agarwal
Angad Singh Agarwal 12 Feb 2017
댓글: Torsten 13 Feb 2017
syms t;
y=(3.7).*(10).^17;
y=3.88*(10).^16.*(t).^(1.5).*exp(-7000./t);
k=solve(y);

  댓글 수: 1

Stephen Cobeldick
Stephen Cobeldick 12 Feb 2017
@Angad Singh Agarwal: I formatted your code correctly by selecting the code text and then clicking the {} Code button. Next time you can do this yourself.

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

답변(2개)

sjoerd
sjoerd 12 Feb 2017
편집: sjoerd 12 Feb 2017
Althought it is not completely clear to me what your question/problem exactly is, I will give it a try I assumed that you want to solve the following equation for t:
3.7e17 = 3.88e16*(t)^(1.5)*exp(-7000./t)
Please note the use of 'e' for the scientific notations which makes its way shorter. Next to this I removed the dots because no need to solve this element wise (only scalar calculations).
The main problem with your code is that you first assign a value to to 'y' and then overwrite this value with the full equation. So introducing a different variable gives the following.
syms t;
result=3.7e17;
y=3.88e16*(t)^(1.5)*exp(-7000/t);
k=solve(y==result);
And this solves for t, (it will give warning that it is not symbolically solved but a numerical approximation is used).
k = 833 (approximately)

  댓글 수: 3

Angad Singh Agarwal
Angad Singh Agarwal 13 Feb 2017
thanks a lot.
Angad Singh Agarwal
Angad Singh Agarwal 13 Feb 2017
showing following error
??? Error using ==> char
Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189
vc = char(v);
Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4
k=solve(y==result);
??? Error using ==> char
Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189
vc = char(v);
Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4
k=solve(y==result);
??? Error using ==> char
Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189
vc = char(v);
Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4
k=solve(y==result);
sjoerd
sjoerd 13 Feb 2017
I think you need to give us a little bit more information, which Matlab version do you use? I am using R2015a and it works fine. Furthermore showing a single error stack is also fine ;)

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


Torsten
Torsten 13 Feb 2017
syms t
result=3.7e17;
y=3.88e16*(t)^(1.5)*exp(-7000/t);
k=solve(y==result,t);
Best wishes
Torsten.

  댓글 수: 2

Angad Singh Agarwal
Angad Singh Agarwal 13 Feb 2017
??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result,t); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result,t); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result,t); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result,t); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result,t); ??? Error using ==> char Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 189 vc = char(v);
Error in ==> solve at 67 [eqns,vars] = getEqns(varargin{:});
Error in ==> Untitled2 at 4 k=solve(y==result,t);
Torsten
Torsten 13 Feb 2017
You seem to use an older MATLAB version.
Take a look into your documentation to see how to use "solve" for your release.
Best wishes
Torsten.

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

Community Treasure Hunt

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

Start Hunting!

Translated by