solving equation with if statements

조회 수: 4 (최근 30일)
antoine
antoine 2020년 1월 17일
댓글: antoine 2020년 2월 22일
Hello
I am trying to solve the following equation given input time and values (y) vectors.
I tried the following
syms theta kappa alpha
if time < alpha
eqn = exp(-kappa*time)==y;
else
eqn = exp(-kappa)*exp(-theta*(time-alpha))==y;
end
vars = [theta kappa alpha];
S=solve(eqn);
but it raises an error...
Conversion to logical from sym is not possible.
I tried to convert alpha into double (i.e. double(alpha) ) in the if statement but it did not work...
Any suggestions?
the data look like :
Picture1.png

채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 17일
syms theta kappa alpha time y real
eqn = y == piecewise(time < alpha, exp(-kappa*time), exp(-kappa)*exp(-theta*(time-alpha)));
vars = [theta kappa alpha];
S = solve(eqn, kappa, 'returnconditions', true); %solve for which variable ??
  댓글 수: 21
Walter Roberson
Walter Roberson 2020년 1월 20일
Yup, but that gives residue in the range of 62, whereas 5087.59871387777093, 0.00292734523205026836, 803477.437304047635 gives you residue in the range of 39.02 which is significantly better. Given that model, alpha should be large, over 100,000.
antoine
antoine 2020년 1월 20일
ahaha.. I get it. thank you!

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

추가 답변 (2개)

antoine
antoine 2020년 1월 18일
time and y are vectors (see plot above for data input). all suggestions are welcome.
I can share the data if it helps
thank you ++
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 1월 18일
Unless time and y are vectors of length 3 exactly, it seems unlikely that there would be any solutions.
It looks to me as if what you have should be a modeling task to estimate parameters rather than a set of simultaneous equations.

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


antoine
antoine 2020년 1월 18일
good not know...Not sure I have the skills to do that.
I really appreciated your input and advices.
  댓글 수: 1
antoine
antoine 2020년 2월 22일
dear Walter
Just realized I forgot to thank you for your help
Problem is fixed! I got my equations working.
(I am know stuck with other timer/loop function : see 'time-dependant iteration through a loop?' if you have time...)

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

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by