Azzera filtri
Azzera filtri

Finding solutions to equations

2 visualizzazioni (ultimi 30 giorni)
Alexander Engman
Alexander Engman il 16 Feb 2016
Commentato: Torsten il 18 Feb 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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Linear Algebra in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by