フィルターのクリア

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 Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by