MATLAB: I have a function returning a 3×1 vector. I now want to plot three graphs for these three outputs.

graphlinspaceplot

Here is my function:
function [ T] = inlamning1( F, m, l )
%Ax = b, A = alla skalärer framför T1,T2,T3 i de tre ekvationerna.
%T = [T1, T2, T3]
%b = skalärerna mg och F
A = [cosd(30), cosd(30), cosd(45); -1*sind(30), sind(30), sind(45); 10*cosd(30), 0, -1*cosd(45).*l];
b = [F*cosd(45)+ m*9.81; -1*F*sind(45) ; -1*F*cosd(45)*10];
T = A\b;
I now want to draw three diffrent graphs showing how T1, T2 and T3 differs for different values of l (l = linspace(5,10))
How can i do that?

Best Answer

Hi
Maybe I'm missing something, but you want to run the function for each value of linspace(5,10) and plot them? Then that's exactly what you should do.
Your script "run_inlamning1.m" (or whichever name you prefer) might then look something like:
% define parameters
F = 1;
m = 1;
Ivec = linspace(5,10);
N = length(Ivec); % 100 by default
% initialize matrix to save results
T_all = zeros(3,N)
% compute all values
for i = 1:N
T_all(:,i) = inlamning1(F,m,Ivec(i));
end
% plot
plot(Ivec,T_all);
xlabel('Ivec');
legend('T1','T2','T3')
In case you're not aware of this: You can get help for all matlab functions by typing "help functionname", e.g. "help plot" directly in matlab. Or "doc plot" for a more extensive help with examples, etc.
Cheers
EDIT Note: if you want T1, T2, T3 to be in different plots, just type "figure" before each plot so the previous one does not get overwritten. You may also want to have a look at "subplot", e.g. subplot(1,3,1) would let you have the three plots side-by-side.
PS: Use the "Code" button when you want to insert code, otherwise it's hardly legible.