Getting Started with Spline Fit in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Fit Matlab
Click For Summary

Discussion Overview

The discussion revolves around using spline fitting in Matlab to create a force vs. position graph from existing force vs. time and position vs. time graphs. Participants are addressing issues related to data alignment, code implementation, and the interpretation of results.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Arman expresses difficulty in understanding how to implement spline fitting in Matlab for his physics experiment.
  • Some participants suggest looking at Matlab documentation for spline functions.
  • There are concerns about the mismatch in the number of x and F values, which could affect the spline fitting process.
  • Arman clarifies that he intends to plot force vs. position rather than force vs. time.
  • Participants discuss the need to align time points when performing spline fitting to ensure accurate representation of the data.
  • One participant notes that extrapolating data outside the time range can lead to incorrect results.
  • Arman shares his results and expresses confusion over discrepancies in calculated work done values, suggesting potential friction effects.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to align the data for spline fitting or on the interpretation of the discrepancies in the work done calculations. Multiple competing views and uncertainties remain regarding the correct implementation and expected outcomes.

Contextual Notes

Participants mention issues related to data extrapolation and the need for consistent time points, but do not resolve these concerns. There are also unresolved questions about the impact of friction on the experimental results.

Who May Find This Useful

Students and practitioners working with data fitting in Matlab, particularly in physics experiments involving force and motion.

Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
Hi Everyone

I am Arman.I am at first grade in Physics and I have trouble to understand Matlab.Now we did Energy Conservation Experiment.I draw x-t and F-t graphs using matlab.Instructor told us we should use spline fit to draw a F-t graph.I don't have a toolbox about it.She told us some code like

"hh=(xx,...)"

It was something like this I don't remember exactly.How can I do that.I can send my graph codes If its necessery.

Sincerely Arman
 
Physics news on Phys.org
Thank you. But I have some trouble again.
 

Attachments

  • Adsız.png
    Adsız.png
    63.9 KB · Views: 556
  • Adsız 1.png
    Adsız 1.png
    60.4 KB · Views: 623
You don't have the same number of values of x as you have of F.
 
I have again problem.
 

Attachments

  • 3.png
    3.png
    65.2 KB · Views: 564
Why are you trying to spline F with respect to x? In the OP, you say you are working with F vs t.
 
I should draw Fx so so sorry
 
My foolish mistake If you can help me I ll be glad.
 
You mean that you plot force vs position, and you need to fit that curve? If that is the case, are all the values of x distinct?
 
  • #10
I have f-t and x-t grpahs and I want to make F-x.But When we want to make to grapsh together there will be a time difference.I mean let's suppose x-t graph is t=0.34 x=1.5 but in F-t graph t=0.35 F=1.5 so the time difference should be fixed and spline fit makes that thing I guess.
 
  • #11
.Basically I want to plot F-x Graph using F-t and x-t graph and spline fit
 
  • #12
If I can't I will going to just take F and x and put them.Which not correct put Its fine enough ??
 
  • #13
Then what you want to do is to spline F at the same points in time as x.

FF = spline(t,F,xx)
 
  • Like
Likes   Reactions: Arman777
  • #14
It worked but graph is so nonsense.I don't know why ?
 
  • #15
what will be that plot code
"yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)"

Example in the Mathlab

My idea
FF = spline(t,F,xx)
plot(t,F,'o',xx,FF)
 
  • #16
Arman777 said:
plot(t,F,'o',xx,FF)
That will give you F vs t, not F vs x. Now that you have FF at the same points in time as x, you can plot
plot(x,F)
 
  • Like
Likes   Reactions: Arman777
  • #17
there's one problem again
1)I don't have 400 N but it still writes 400 N I don't know why ?

By the way thanks
 

Attachments

  • 4.png
    4.png
    59.5 KB · Views: 526
  • 5.png
    5.png
    39.6 KB · Views: 526
  • #18
Could you show the plot
plot(t,F,'o',xx,FF)
 
  • #19
ok
 

Attachments

  • Adsız 6.png
    Adsız 6.png
    37.4 KB · Views: 585
  • #20
It doesn't work because you are extrapolating data outside the time range of the force measurements. I don't understand how come you have position data at such different times than force data.
 
  • #21
Let me send my data graphs each of them.And Data.If you want you can look.
 

Attachments

  • #22
>> t=position_time(:,1);
>> x=position_time(:,2);
>> t=force_time(:,1);
>> F=force_time(:,2);
>> tt=0.8:3.1;
>> tt=0.8:0.1:3.1
FF=spline(t,F,tt);
>> plot(x,F);

It worked I can send the image its consist with the result.Thank you
 
  • #23
Is it consist with the two graph that I send you ?
And I have a problem My graph says the work done is 0.26 J using trapz code.
I calculated the ΔKE=1/2mΔv2 Which gave me 0.42 J
and the real result using mgsinθx=W gave me 0.34 J

It means theoritaical value is 0.34 J , my experimental graph value is 0.26 J , experimental speed value is 0.42 J

There will be a friction and ΔKE-Wf=0.26J so 0.16 J gone to friction maybe ??

But there's also friction that we didnt reduce from experimental value which I thing that means I found the result with %10-15 error

Is that ok ?
 

Attachments

  • Force-distance.png
    Force-distance.png
    13.5 KB · Views: 559
Last edited:

Similar threads

  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K