Help using solve function

1 回表示 (過去 30 日間)
Juan Pedro Martinez
Juan Pedro Martinez 2022 年 4 月 21 日
回答済み: David Hill 2022 年 4 月 21 日
Hello. I want to run the following code:
function [ema]=EMA(ec,fc,gamma,model)
if strcmp(model,'LL')==1
eh=1;
ema=solve((em-eh)/(em+gamma*eh)-sum(fc.*((ec-eh)./ec+gamma*eh))==0,em);
elseif strcmp(model,'MG')==1
eh=ec(fc==max(fc));
ema=solve((em-eh)/(em+gamma*eh)==sum(fc.*((ec-eh)./ec+gamma*eh)),em);
elseif strcmp(model,'B')==1
ema=solve(0==sum(fc.*((ec-em)./ec+gamma*em)),em);
end
I receive the following error:
Unrecognized function or variable 'em'.
I would think that solve assigns em as variable. I do not have the symbolic math toolbok yo use the function syms, which I have seen in some answers or documentation. Is there an alternative? I would guess so because solve does not require that toolbox.
If I try and replace the equation with a function handle as below I get the error
Operator '==' is not supported for operands of type 'function_handle'.
Thank you
fun=@(em) (em-eh)/(em+gamma*eh)-sum(fc.*((ec-eh)./ec+gamma*eh))
ema=solve(fun==0,em);

回答 (1 件)

David Hill
David Hill 2022 年 4 月 21 日
fun=@(em) (em-eh)/(em+gamma*eh)-sum(fc.*((ec-eh)./ec+gamma*eh));
guess=5;%what is your best guess for what ema should be?
ema=fzero(fun,guess);

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by