필터 지우기
필터 지우기

Finding solutions to equations

조회 수: 2 (최근 30일)
Alexander Engman
Alexander Engman 2016년 2월 16일
댓글: Torsten 2016년 2월 18일
Hi!
I have a question regarding solving functions. I have a specific function I want to solve but rather than post it here, I will give a general description of my problem.
Lets say I have a function: eq1=integral from 0 to 2 of (k*x^2)/(0.2+k) and another function: eq2=(1+k)
The variable x represents the limits of the integral.
I want to solve eq1=eq2 for k>0, that is I want to find the exact value of the positive number k so that eq1=eq2.
My first thought was to put everything in a for-loop and let the loop generate values of k until it finds a value that satisfies the statement.
This is what I have so far:
x=0:2; %integral values for k=0:10000 %arbitrary positive k value eq1=(k*x^2)/(0.2+k) %first equation eq2=(1+k) %second equation if integral(eq1,0,2)==eq2 disp(k) end; end;
I am fairly certain that this method could work with a bit of effort but I don't know how to correctly express in the for loop that I want it to compare eq2 and the integral value of eq1 from x=2 to x=0.
Help appreciated!
Thanks.
PS. I am not sure that the two equations used in the example do have a solution for k, it was just used to show my problem.

채택된 답변

Torsten
Torsten 2016년 2월 16일
편집: Torsten 2016년 2월 16일
k0=1.0;
fun_int=@(x,k) k.*x.^2./(0.2+k);
fun=@(k) integral(@(x)fun_int(x,k),0,2,'ArrayValued',true)-(1+k);
k=fzero(fun,k0);
Best wishes
Torsten.
  댓글 수: 4
Alexander Engman
Alexander Engman 2016년 2월 17일
Could you please give me a brief explanation of how this code works?
Thanks!
Torsten
Torsten 2016년 2월 18일
%define starting guess for k
k0=1.0;
% define function to be integrated
fun_int=@(x,k) k.*x.^2./(0.2+k);
% define function you want to equate to zero (eqn1-eqn2=0)
fun=@(k) integral(@(x)fun_int(x,k),0,2,'ArrayValued',true)-(1+k);
% determine zero of function
k=fzero(fun,k0);
Best wishes
Torsten.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by