MATLAB Answers

how can I do Iteration in matlab

I have an equation of the form

a(x) + x.da/dx = 2x , x= 1:1:12

f(x) is known and has different values for different x. My question is how can I find values of 'a' in matlab through iteration. Am new to matlab and any help is highly appreciated.


Log in to comment.

2 Answers

Answer by Azzi Abdelmalek
on 17 Nov 2012
Edited by Azzi Abdelmalek
on 17 Nov 2012
 Accepted Answer

save this function with the name dif_eq

function da=dif_eq(x,a,tim,f)

then call the function:

 t=[0.1:10]; % time vector
 x0=0; % initial condition
 f=rand(1,numel(t)); % your vector f, same length as vector time t
 [X,A]=ode45(@(x,a) dif_eq(x,a,t,f),t,x0);

  1 Comment

Many many thanks ...don't have words for your help....this was so troublesome...

Log in to comment.

Answer by Azzi Abdelmalek
on 17 Nov 2012
Edited by Azzi Abdelmalek
on 17 Nov 2012

save this funnction with the name dif_eq

function da=dif_eq(x,a)
f=sin(x); for example

then type in Matlab command

[x,res]=ode45(@dif_eq,[1 12],0)


Yes, I did that my actual 'f' is not function actually it is collection of different values. such as 0.4 0.25 0.6.....

Thanks Azziz , I understand your function but 'a' itself isn't known and that's my problem.

Ede, the problem is not a, we are looking for a. I can't use f with different values in the equation. If I find something I will post it, or someone else will do.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!