Finding solutions to equations

2 次查看(过去 30 天)
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