how to have a changing input in a function

I wrote a script with a function
ex: function [DV] = deltaV(debris1, debris2, t1,t2,t1_0,t2_0,rE,mu,J2)
I have to plot the function with an increasing t2 or an increasing debris2(3) (debris1 and debris2 are vectors)
how can I do that?

 Accepted Answer

t2 = linspace(0, 10, 100);
DV = zeros(size(t2));
for k = 1:numel(t2)
DV(k) = deltaV(debris1, debris2, t1, t2(k), t1_0, t2_0, rE, mu, J2);
end
plot(t2, DV);

2 Comments

Thank you
It works for t2 even though I have to use it for small numbers, but I can't make it work for debris2(3).
Do I have to use it in the same way even if debris2 is a vector?
debris2 = rand(1, 3);
DV = zeros(1, 100);
for k = 1:100
debris2(3) = rand;
DV(k) = deltaV(debris1, debris2, t1, t2, t1_0, t2_0, rE, mu, J2);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 26 Jun 2021

Commented:

Jan
on 28 Jun 2021

Community Treasure Hunt

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

Start Hunting!