LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2006, 12:58 PM   #1
Leha208
LQ Newbie
 
Registered: Apr 2006
Posts: 1

Rep: Reputation: 0
matlab help needed!!


Hi!
I am new to here. My friend show me this useful website. I hope anyone here could help me out. Ive tried to learn MATLAB. When i test it with my lecturer's file, i didnt score full mark. Please guide me through.
build-in function-functask2=sinh(x)-x.^2+x+1, xvalues=[1x50 double].
1) i need to compute the function at these xvalues and store in yvalues.
2) find best fit,quadratic n cubic to these values. Store the polynomial coefficient in linecoef, quadcoef and cubiccoef.
3) find new vector of x values,xnew,where there are 5 equispaced points betw each of the values in xvalues.
4) evaluate the polynomials and the function at xnew, store in yline, yquad, ycubic and yfunc.
5) do a cubic spline interpolation betw xvalues, yvalues, to find output values ynew at xnew.
6) overlay all 5 curves in a single plot.

my file is:
function out2=task2(in2)

%%% Compute what is originally in the workspace for task2.
out2=in2;

%%% Let x be a cell array containings the xvalues.
%%% Evaluate the function at x and compute them
%%% in yvalues.
x=in2.xvalues;
out2.yvalues=eval(in2.functask2);

%%% Compute the best fit straightline,
%%% quadractic and cubic to those yvalues.
%%%
out2.linecoef= polyfit(x,out2.yvalues, 1);
out2.quadcoef=polyfit(x,out2.yvalues,2);
out2.cubiccoef=polyfit(x,out2.yvalues,3);
r=numel(x);
xnew=linspace(x(1),x(end),6*(r-1)+ 1);
out2.xnew=xnew;
out2.yline=polyval(out2.linecoef,xnew);
out2.yquad=polyval(out2.quadcoef,xnew);
out2.ycubic=polyval(out2.cubiccoef,xnew);
x = xnew;
out2.yfunc=eval(in2.functask2,xnew);
ynew=spline(in2.xvalues, out2.yvalues, x);
out2.ynew=ynew;
figure(2); clf reset;
plot(xnew,ynew,'b', xnew,out2.yline, 'g',...
xnew,out2.yquad, 'y', xnew, out2.ycubic, 'k',...
xnew, out2.yfunc, 'm');
title( in2.functask2);
legend('vector', 'best fit line', 'quadratic',...
'cubic', 'function');


My up-2-date file is:
function out2=task2(in2)
out2=in2;
x=in2.xvalues;
out2.yvalues=eval(in2.functask2);

% To find the best fit straightline, quadratic
% and cubic at yvalues.
% Store them as polynomial coefficients in linecoef,
% quadcoef and cubiccoef respectively.
out2.linecoef= polyfit(x,out2.yvalues, 1);
out2.quadcoef=polyfit(x,out2.yvalues,2);
out2.cubiccoef=polyfit(x,out2.yvalues,3);

% To find a new vector, xnew.
% xnew contains values in x.
% xnew has 5 equispaced points between
% each of the values in x.
[x_val,y_val]= size(x);
% x_val the number of rows and y_val the number
% of columns in x.
aa=cell(1,(y_val-1));
% creates a 1-by-(y_val-1) cell array of empty matrices.
for i=1y_val-1)
if i==1
aa{i}=linspace(x(i),x(i+1),7);
else % if i is not equal to 1
xx=linspace(x(i),x(i+1),7);
xxx=xx(2:end);
aa{i}=xxx;
end
end
xnew=[aa{1:end}];
out2.xnew=xnew;
% To evaluate the polynomials and functask2 at xnew.
% store them in yline, yquad, ycubic and yfunc
% respectively.
out2.yline=polyval(out2.linecoef,xnew);
out2.yquad=polyval(out2.quadcoef,xnew);
out2.ycubic=polyval(out2.cubiccoef,xnew);
x = xnew;
out2.yfunc=eval(in2.functask2,xnew);

% To perform cubic spline interpolation between
% xvalues and yvalues.
% computes the values at xnew and store them at ynew.
ynew=spline(in2.xvalues, out2.yvalues, xnew);
out2.ynew=ynew;
% To plot a graph on figure(2) showing the 5 curves.
figure(2); clf reset;
plot(xnew,out2.ynew,'b', xnew,out2.yline, 'g',...
xnew,out2.yquad, 'y', xnew, out2.ycubic, 'k',...
xnew, out2.yfunc, 'm');
title(in2.functask2);
legend('vector', 'best fit line', 'quadratic',...
'cubic', 'function');
cheers!! please help me out.

ZUs.
 
Old 04-20-2006, 05:05 AM   #2
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606

Rep: Reputation: 53
Have you read the LQ website rules?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Matlab 6.5 !! Help!! rcnow Linux - Software 11 05-10-2007 04:41 AM
Matlab wwnexc Linux - Software 8 03-21-2006 02:43 AM
Terminal cmd for starting Matlab M-file editor without starting matlab fubzot Linux - Software 2 02-15-2005 07:49 AM
MatLab in Linux MaMatO Linux - Software 8 01-02-2004 09:34 AM
Matlab safrout Programming 3 04-13-2002 04:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration