help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using fsolve() for a function involving quad()?


From: Minyu Chen
Subject: Re: Using fsolve() for a function involving quad()?
Date: Tue, 12 Jun 2007 19:30:17 +0100

Thank you very much.

For my case, this reply by JWE in someone else's post works: http:// www.nabble.com/How-to-share-variables-between-functions-p9812339.html

Here are my entire test:

function w=f(x,y)
w=x.*y;
end

function z=g(x)
z=quad(@(y)f(x,y),0,1)+2;
end

And "fsolve('g',0)" return the correct answer 4.

Thanks,
Minyu Chen

On Jun 12, 2007, at 7:05 PM, David Grohmann wrote:

Minyu Chen wrote:
Dear all:

I am sorry that the question might sound a bit silly.

I need to solve a function involving integration, so I think I need both quad()--for the integration and fsolve()--for the equation. However, the integrand involve the unknown.

For a trivial example, I want to solve: x+\int_{0}^{1}x*y dy=0

I was thinking of taking a function:

function w=f(y)
w=x.*y;

on this line what 'x' do you expect to have? you need to pass your x in from g() to f() if that is the x you though tit would be.
endfunction

Then I use another function:

function z=g(x)
z=quad('f',0,1)+x;
endfunction

Then I use: fsolve('g',0.5). But it didn't work.

The error message is that the "x" is not defined in my f function. However, I called "f" only in the function "g", and the x in the function "g" is already initialized as 0.5 in the searching. What went wrong?

Thank you very much.

Thanks,
Minyu Chen
_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave



--
David Grohmann
Senior Student Associate
Applied Research Lab : UT Austin : ESL - S206
Office: 512-835-3237





reply via email to

[Prev in Thread] Current Thread [Next in Thread]