0% found this document useful (0 votes)
6 views

Coding Notes

Code notes

Uploaded by

ablemelschools
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Coding Notes

Code notes

Uploaded by

ablemelschools
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

> plot (x,y)

error: 'x' undefined near line 1, column 7


>> x = 0:0.1:5; y = 4*x.^2;
>>
>> x = 0:0.1:5; y = 4*x^2
error: for x^y, only square matrix arguments are permitted and one argument must be scalar. Use .^ for elementwise power.
>> x = 0:0.1:5; y = 4*x.^2
y=
0 0.0400 0.1600 0.3600 0.6400 1.0000 1.4400 1.9600 2.5600 3.2400 4.0000 4.8400 5.7600 6.7600 7.8400
9.0000 10.2400 11.5600 12.9600
14.4400 16.0000 17.6400 19.3600 21.1600 23.0400 25.0000 27.0400 29.1600 31.3600 33.6400 36.0000 38.4400
40.9600 43.5600 46.2400 49.0000 51.8400 54.7600
57.7600 60.8400 64.0000 67.2400 70.5600 73.9600 77.4400 81.0000 84.6400 88.3600 92.1600 96.0400 100.0000

>> plot(x,y)
>> x = linspace(0,360,25); y = sind(x);
>> plot(x,y,'-gp')
>>
>> x = 0:25; y = sqrt(x);
>> plot(x,y,'ob:')
>>
>> x = 0:10; y = 5*x-3;
>> plot(x,y,'--kd','LineWidth',3,'MarkerSize',10,'MarkerEdgeColor',r, 'MarkerFaceColor','g')
error: 'r' undefined near line 1, column 65
>> plot(x,y,'--kd','LineWidth',3,'MarkerSize',10,'MarkerEdgeColor','r', 'MarkerFaceColor','g')

>> @ (x) f(x)


ans =

@(x) f (x)

>> @(x) 8*x.^2+5*cos(x)


ans =

@(x) 8 * x .^ 2 + 5 * cos (x)

>> fplot(@(x) sin(x), [-pi,pi])


>> my_func = @(x) cos(x);
>> fplot(my_func, [-pi,pi])
>> my_func = @(x) cos(x);
>> my_func = @(x) cos(x);

>> x = 0:10; y=x.^2; u = x; v = u; t = x; h = sqrt(t);


>> plot(x,y,u,v,t,h)
>> plot(x,y,':rd',u,v,'--gp',t,h)
>> Variables are coupled xy uv th
error: 'Variables' undefined near line 1, column 1
>> plot(x,y,':rd',u,v,'--gp',t,h)
>> plot(x,y)
>> hold on
>> plot(u,v)
>> plot(t,h)
>> hold off
>>
>> x = 0:10; y=x.^2; u = x; v = u; t = x; h = sqrt(t);
>> plot(x,y)
>> line (u,v)
>> line(t,h)
>>
>> x = 0:10; y = sqrt(x);
>> plot (x,y)
>> x = 0:10; y = sqrt(x);
>> plot (x,y)
>>
>> xlabel('x axis')
>> ylabel ('y axis')
>> title('y vs x')
>> text(2,2,'text on graph')
>>
>> legend('sqrt(x)','NE')
warning: legend: ignoring extra labels.
warning: called from
legend>parse_opts at line 831 column 9
legend at line 216 column 8

>> axis([0,15,0,5])
>> axis equal
>> axis squar
warning: axis: unknown option 'squar'
warning: called from
axis>__axis__ at line 363 column 9
axis at line 179 column 7

>> axis square


>> axis tight
>> grid on
>> grid off
>>
>> text(6,1,'\bfBold \itItalic\ rmNormal', 'Rotation', 30)

>> my_func = @(x) x.^4 - 2*x.^3 + 1.3*x.^2 - 0.3*x + 0.02


my_func =

@(x) x .^ 4 - 2 * x .^ 3 + 1.3 * x .^ 2 - 0.3 * x + 0.02

>> subplot(2,1,1)
>> fplot(myfunc,[-3,4])
error: 'myfunc' undefined near line 1, column 7
>> fplot(my_func,[-3,4])
>> subplot(2,1,2)
>> fplot(my_func,[0,1])
>>
my_func = @(x) (x.^2 - 6*x +7)./(x.^3-8);
>> x1 = 0:0.1:1.9; x2 = 2.1:0.1:4;
>> y1 = my_func(x1); y2 = my_func(x2);
>> plot(x1,y1,x2,y2)
>>x = linespace(-pi,2*pi,100);
error: 'linespace' undefined near line 1, column 5
>> x = linspace(-pi,2*pi,100);
>> f = sin(2*x).*cos(0.5*x).^2
f=

Columns 1 through 23:

df
error: 'df' undefined near line 1, column 1
>> diff(f)
>>
>> derv(f)
error: 'derv' undefined near line 1, column 1
>> f
f=

>> df = diff(f,1)
df =

>> plot (x,f,'-',x,df,'--')


error: __plt2vv__: vector lengths must match
error: called from
__plt__>__plt2vv__ at line 489 column 5
__plt__>__plt2__ at line 248 column 14
__plt__ at line 115 column 16
plot at line 240 column 10
>> legend('f(x)','df(x)/dx')
warning: legend: ignoring extra labels.
warning: called from
legend>parse_opts at line 831 column 9
legend at line 216 column 8

>> f(100)=[]
f=

>> plot (x,f,'-',x,df,'--')


error: __plt2vv__: vector lengths must match
error: called from
__plt__>__plt2vv__ at line 489 column 5
__plt__>__plt2__ at line 248 column 14
__plt__ at line 115 column 16
plot at line 240 column 10
>>
>> A = [1:3:34]
A=

1 4 7 10 13 16 19 22 25 28 31 34

>> B = 1:3:34
B=

1 4 7 10 13 16 19 22 25 28 31 34
>> C = linspace(0,12,11)
C=

0 1.2000 2.4000 3.6000 4.8000 6.0000 7.2000 8.4000 9.6000 10.8000 12.0000

>> v = 41:-3:29, w=17:4:37


v=
41 38 35 32 29
w=
17 21 25 29 33 37
>> u= {w v]
error: parse error:

syntax error

>>> u= {w v]
^
>> u = [w v]
u=
17 21 25 29 33 37 41 38 35 32 29

>> B = [linspace(1,10,10); 1,1,10]


error: vertical dimensions mismatch (1x10 vs 1x3)
>> B = [linspace(1,10,10); 1:1:10]
B=

1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10

>> C = linspace(1,5,5)
C=
1 2 3 4 5
>> linspace(6,10,5)
ans =

6 7 8 9 10
>> A = zeros(3,5)
A=
>> B = ones(5,2)
B=
>> D = eye(3)
D=
Diagonal Matrix
>> D = eye(3,5)
D=

Diagonal Matrix
>> '
error: parse error:

unterminated character string constant


>>> '
^
>> C'
ans =
>> E = [zeros(3,4) [8;7;6]]
E=
>> A = 2:2:24
A=
2 4 6 8 10 12 14 16 18 20 22 24
>> A(:)
ans =
>> E(:,2)
ans =
>> E(2,:)

t = linspace(0, 4, 100);
>> x = 4.219*(exp(-1.58*t)-exp(-6.32*t));
>> v = 26.67*exp(-6.32*t)-6.67*exp(-1.58*t);
>>
>> subplot(2,1,1)
>> plot(t,x)
>> xlabel('time (s)')
>> ylabel('position (m)')
>> subplot(2,1,2)
>> plot(t,v)
>> xlabel('time (s)')
>> ylabel('velocity (m/s)')
>>
>>
>> x1 = 0:0.1:8;
>> x2 = 8:0.1:12;
>> x3 = 12:0.1:20;
>> Va = 400 -200*x1;
>> Vb(1:length(x2))=-1200;
>> Vc=-250*x3+5000;
>> Ma =-100*x1.^2+400*x1;
>> Mb =-1200*x2+6400;
>> Mc =-125*(x3-12).^2+2000*x3-32000;
>>
>> x = [x1 x2 x3];
>> V = [Va Vb Vc];
>> M = [Ma Mb Mc];
>>
>> subplot(2,1,1)
>> plot(x,V)
>> xlabel('x (ft)')
>> ylabel('Shear Force (lb)')
>> subplot(2,1,2)
>> plot(x,M)
>> xlabel('x (ft)')
>> ylabel('Bending Moment (lb-ft)')

You might also like