필터 지우기
필터 지우기

How to find numerical roots for multivariable functions

조회 수: 1 (최근 30일)
muly san
muly san 2014년 4월 23일
댓글: Star Strider 2014년 4월 23일
Hi, I want to draw some graphs for my work. This is my function:
function H_star=RHS1(H,h,theta,A);
a=A.*((1.-H)./H).^(1-theta);
if (1/a)*(1-1/a)>h;
H_RHS=1/(2*a)-h^2*a^3/(2*(a-1)^2);
else
H_RHS=0;
end
H_star=H_RHS-H;
end
I want to find a root for this function (as function of H). I tried to do it by this command (I set examples values for the parameters):
fzero (inline('RHS1(H,0.1,0.6,1.1)'),0.5)
By this way I succeed to get an answer.
My question is how I can draw this fixed point as function of one of the parameters. For example, I want to plot the fixed point as function of A. I tried to do it in this way:
j=1;
for A=0.5:0.01:2;
H_star(j)=fzero (inline('RHS1(H,0.1,0.6,A)'),0.5)
j=j+1;
end
But I get the message "Not enough inputs to inline function."
In adition, I want to get numeric derivatives of this fixed point according to the parameters.
Thanks!

답변 (1개)

Star Strider
Star Strider 2014년 4월 23일
편집: Star Strider 2014년 4월 23일
I suggest this as a possible solution:
  • Define h and theta in your workspace,
  • Define A = 0.5:0.01:2; in your workspace,
  • Create a for (or while) loop for j,
  • Replace ‘for A=...’ with for k = 1:length(A)
  • Create the anonymous function (instead of using the inline function) in the loop after the for k = 1:length(A) statement and then call fzero with it:
f = @(H) @RHS1(H,h,theta,A(k));
H_star(i,k) = fzero(f, 0.5);
This should get you started.
NOTE: I did not run your code, so my suggestions are untested but should work. Also, it is best not to use i and j as index counters, because MATLAB uses them for its imaginary operators.
  댓글 수: 2
muly san
muly san 2014년 4월 23일
Thank you very much! I will try it..
Star Strider
Star Strider 2014년 4월 23일
My pleasure!

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by