Alex
Posts:
4
Registered:
12/6/12
|
|
Re: I'm new to matlab; why is this function wrong?
Posted:
Dec 6, 2012 11:54 AM
|
|
"Sargondjani" wrote in message <k9qhho$obr$1@newscl01ah.mathworks.com>... > you can only define functions inside a function-file and not in a script (dont ask me why, because it bothered me too, but matlab developers usually have good reasons for doing such things) > > so either: > 1) transform your script into a function: > start with: "function my_script()" and end with "end" > > 2) define the function in an m-file that you call in your script > > i hope this helps...
Thanks Sargondjani.
Now when I run this script:
plot(0,0,'yX') hold on for n = 1:1:730 del_t=24*3600; [R V] = orbits(Ro, Vo, del_t); plot(R(1),R(2),'go') hold on; Ro=R; Vo=V; end
calling function:
function [R V] = orbits(Ro, Vo, del_t) Ro=[1.5e11, 0]; Vo=[0, 2*pi*Ro(1)/(365*24*60*60)]; G = 1.67e-11; del_t=24*3600; Ms = 1.97e30; d = (Ro(1)^2 + Ro(2)^2)^(3/2); a = -(G*Ms/d)* Ro; V = Vo + a * del_t; R = Ro + Vo * del_t + .5 * a * del_t^2; end
I get Error in ==> two_dimensional_ac at 5 [R V] = orbits(Ro, Vo, del_t);
|
|