필터 지우기
필터 지우기

Solving an Equation in Matlab

조회 수: 2 (최근 30일)
Sean Sarran
Sean Sarran 2022년 10월 15일
편집: John D'Errico 2022년 10월 15일
I am trying to solve the following for t:
(16.68t) - ((16.68 - 0)*(1-(exp(-0.21t)))/0.21) - (8.5) = 0
  댓글 수: 4
dpb
dpb 2022년 10월 15일
t = fzero(@(t)16.68*t - (16.68*(1-(exp(-0.21*t)))/0.21) - 110.85,10)
t = 10.9277
fzero will find the nearest root; change the starting value...
Sean Sarran
Sean Sarran 2022년 10월 15일
Thank you. This worked!!

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

답변 (1개)

John D'Errico
John D'Errico 2022년 10월 15일
편집: John D'Errico 2022년 10월 15일
Sounds like you got an answer that worked, but let me expand. You have a function:
f = @(t)16.68*t - (16.68*(1-(exp(-0.21*t)))/0.21) - 110.85;
And you need to find a zero, that is, a value of t such that f(t)==0.
First, ALWAYS PLOT EVERYTHING. Then, find something more to plot, if plotting everything was not sufficient. And when done, think about what you see. Does what you see make sense?
fplot(f)
So no solution in the interval [-5,5], the default for fplot.
fplot(f,[-20,20])
grid on
And that tells us there will be two roots. A negative one, and a positive one. One will be near -5, and the other near +10. Well, at LEAST two roots. If we looked further out, we may find more.
If you give fzero only ONE starting value, then it tries to find a root, but it won't really care which one it finds. A root is a root for god sakes! You asked for a root. ;-) For example:
[xsol,fval] = fzero(f,0)
xsol = -6.2371
fval = 1.4211e-14
You can see it decided to find the negative root, but that is just the one it found.
If you want to find the positive one, then use a bracket for fzero that is positive. A bracket is a pair of values for x, such that the function is positive at one end, and negative at the other.
[xsol,fval] = fzero(f,[0,1000])
xsol = 10.9277
fval = 2.8422e-14
This will insure that fzero always finds the positive root.
  댓글 수: 1
Sean Sarran
Sean Sarran 2022년 10월 15일
Great advice. It worked. Thank you.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by