Finding solutions to equations

4 visualizaciones (últimos 30 días)
Alexander Engman
Alexander Engman el 16 de Feb. de 2016
Comentada: Torsten el 18 de Feb. de 2016
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.

Respuesta aceptada

Torsten
Torsten el 16 de Feb. de 2016
Editada: Torsten el 16 de Feb. de 2016
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 comentarios
Alexander Engman
Alexander Engman el 17 de Feb. de 2016
Could you please give me a brief explanation of how this code works?
Thanks!
Torsten
Torsten el 18 de Feb. de 2016
%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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by