Help using solve function
3 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
David Hill
on 21 Apr 2022
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);
0 Comments
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!