how can I define a interpolation-based function f(t,x), which is time- and space-dependent (2024)

Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Posted Oct 3, 2010, 12:13 a.m. EDT 7 Replies

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (1)

Benjamin Wayne

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

I need to define and use this function in the PDE. Specifically, if t=0:0.1:1, x=0:0.1:1, I have the data for all the grid points, and would like to define a function f(t,x) so that I can get the value by interpolation for non-grid points.

In comsol, it seems that only f(x) is allowed. Any suggestions are highly appreciated. thanks.

7 Replies Last Post Oct 3, 2010, 2:40 p.m. EDT

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (2)

Jean-Francois Leon

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

well I dont know if you are right in your understanding of what comsol can do with space and time ..BUT
f you have no more than 2 space dimension in your problem, a trick will be to use a "comsol space dimension" as the time of yout problem.. it just labeled y or z and not t... :-)

The shock tube example [ in the doc or in the model example section I dont remember[precisely] is a good example of using such a "comsol space dimension " in lieu of time.

JF

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (3)

Benjamin Wayne

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

Hi JF

Thanks for your great help. Following your suggestion, I defined an interpolation-based function f(t,x), however, I encountered some fatal errors and comsol stopped working.

My problem is very simple so that I used the "PDE Coefficient Form" directly. My PDE (time-dependent, 1-D space dimension) is of the standard form: da*ut-c*uxx+a*u+be*ux=f, but I need to define "be" in front of ux using an interpolation-based function f(t,x) based on "BFile.txt": "t" is between 1 and 10, and "x" is between 0 and 1. The first few rows in the text file "BFile.txt" are the following:

1.0000000e+000 0.0000000e+000 9.8000000e-001
1.0000000e+000 5.0000000e-002 1.1000000e-001
1.0000000e+000 1.0000000e-001 2.2000000e-001
1.0000000e+000 1.5000000e-001 3.3000000e-001
1.0000000e+000 2.0000000e-001 4.4000000e-001
1.0000000e+000 2.5000000e-001 5.5000000e-001
1.0000000e+000 3.0000000e-001 6.6000000e-001
1.0000000e+000 3.5000000e-001 7.7000000e-001

Could you or someone else in this forum help me out? It's frustrating to be stuck here. Thanks a million.

P.S. I thought about using inline functions: f(t,x)=interp2(matT,matX,matZ,t,x). However, I don't know how to script it in matlab since I am not using GUI of comsol and prefer to do it all in matlab scripts. Do you know how I can do it? Thanks.

P.S. The error message is:

??? Java exception occurred:
Exception:
com.femlab.server.MlError: Error using ==> feval
Undefined command/function 'f'.
(rethrown as com.femlab.jni.FlNativeException)
Messages:
Error using ==> feval
Undefined command/function 'f'.

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (4)

Benjamin Wayne

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

Hi JF and others,

Please discard my previous post. I just figured it out. I used "fem1" but defined the function f(t,x) for "fem". Of course, it didn't work ...

But now I got a new problem: "Non monotonous interpolation grid", which I don't quite understand.

As you can see from my previous post, my data are sorted and stored in "BFile.txt" in the following way: I first sort "t" from 1 to 10, and then for each value of "t", I sorted "x" from 0 to 1. So why I got this message? Does anyone here know how to fix it? Thank you very much.


Hi JF

Thanks for your great help. Following your suggestion, I defined an interpolation-based function f(t,x), however, I encountered some fatal errors and comsol stopped working.

My problem is very simple so that I used the "PDE Coefficient Form" directly. My PDE (time-dependent, 1-D space dimension) is of the standard form: da*ut-c*uxx+a*u+be*ux=f, but I need to define "be" in front of ux using an interpolation-based function f(t,x) based on "BFile.txt": "t" is between 1 and 10, and "x" is between 0 and 1. The first few rows in the text file "BFile.txt" are the following:

1.0000000e+000 0.0000000e+000 9.8000000e-001
1.0000000e+000 5.0000000e-002 1.1000000e-001
1.0000000e+000 1.0000000e-001 2.2000000e-001
1.0000000e+000 1.5000000e-001 3.3000000e-001
1.0000000e+000 2.0000000e-001 4.4000000e-001
1.0000000e+000 2.5000000e-001 5.5000000e-001
1.0000000e+000 3.0000000e-001 6.6000000e-001
1.0000000e+000 3.5000000e-001 7.7000000e-001

Could you or someone else in this forum help me out? It's frustrating to be stuck here. Thanks a million.

P.S. I thought about using inline functions: f(t,x)=interp2(matT,matX,matZ,t,x). However, I don't know how to script it in matlab since I am not using GUI of comsol and prefer to do it all in matlab scripts. Do you know how I can do it? Thanks.

P.S. The error message is:

??? Java exception occurred:
Exception:
com.femlab.server.MlError: Error using ==> feval
Undefined command/function 'f'.
(rethrown as com.femlab.jni.FlNativeException)
Messages:
Error using ==> feval
Undefined command/function 'f'.

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (5)

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

Hi
the first parameter must be strictly increasing or decreasing, in the worst case just add a "counter" 1:n variably and define it to a dummy variable you do not need to use anywhere else

--
Good luck
Ivar

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (6)

Benjamin Wayne

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

Hi Ivar,

Thank you so much for your great help. If I define another dummy variable "count" (1:n), shall I also include it into my function, which will become f(count,t,x)?

Maybe it is easier to use inline function: f(t,x)=interp2(matT,matX,matZ,t,x). However, I don't know in GUI, how can I import the Matlab matrices: "matT" and "matX" and "matZ", which are stored on my computer. If possible, can you give me some help about how I can define such an inline function and make these matrices accessible in comsol? Thank you very much.

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (7)

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

Hi

Sorry, I was also confused here, my remark is related to parametric sweep multiple variable entries, where the first one must be strictly increasing and decresing. Your case is a bit more tricky, the error message is close and its more or less the same issue.

your text file has the first column set to 1, if this is used for the interpolation it is as if there are many settings for the same point. Either you have a coumn index error, or I have missed something also possible (I do not have access to matlab+3.5 from home)

--
Good luck
Ivar

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (8)

Benjamin Wayne

Send Private Message Flag post as spam

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago

Hi Ivar

Sorry for the confusion. My text file has three columns, for "t", "x", and "f(t,x)", respectively for all grid points. I put more entries below. The first column, "t", ranges from 1 to 10; the second, "x", from 0 to 1. As a beginner of comsol, I don't know how to successfully define an interpolation-based function f(t,x). Any help on this is highly appreciated. Thanks a lot.

code:
clear fcns
fcns{1}.type='interp';
fcns{1}.name='f';
fcns{1}.filename='.\BFile.txt';
fcns{1}.fileindex='1';
fcns{1}.method='linear';
fcns{1}.extmethod='const';
fcns{1}.defvars='true';
fem1.functions = fcns;

some entries of "BFile.txt".
1.0000000e+000 0.0000000e+000 9.8000000e-001
1.0000000e+000 5.0000000e-002 1.1000000e-001
1.0000000e+000 1.0000000e-001 2.2000000e-001
1.0000000e+000 1.5000000e-001 3.3000000e-001
1.0000000e+000 2.0000000e-001 4.4000000e-001
1.0000000e+000 2.5000000e-001 5.5000000e-001
1.0000000e+000 3.0000000e-001 6.6000000e-001
......
1.2000000e+000 0.0000000e+000 9.9100000e-001
1.2000000e+000 5.0000000e-002 1.3200000e-001
1.2000000e+000 1.0000000e-001 2.6400000e-001
1.2000000e+000 1.5000000e-001 3.9600000e-001
1.2000000e+000 2.0000000e-001 5.2800000e-001
1.2000000e+000 2.5000000e-001 6.6000000e-001
1.2000000e+000 3.0000000e-001 7.9200000e-001
1.2000000e+000 3.5000000e-001 9.2400000e-001
1.2000000e+000 4.0000000e-001 1.0560000e+000
......
1.3000000e+000 0.0000000e+000 9.9650000e-001
1.3000000e+000 5.0000000e-002 1.4300000e-001
1.3000000e+000 1.0000000e-001 2.8600000e-001
1.3000000e+000 1.5000000e-001 4.2900000e-001
1.3000000e+000 2.0000000e-001 5.7200000e-001
1.3000000e+000 2.5000000e-001 7.1500000e-001
1.3000000e+000 3.0000000e-001 8.5800000e-001
1.3000000e+000 3.5000000e-001 1.0010000e+000
.......
1.0000000e+001 0.0000000e+000 1.4750000e+000
1.0000000e+001 5.0000000e-002 1.1000000e+000
1.0000000e+001 1.0000000e-001 2.2000000e+000
1.0000000e+001 1.5000000e-001 3.3000000e+000
1.0000000e+001 2.0000000e-001 4.4000000e+000
1.0000000e+001 2.5000000e-001 5.5000000e+000
1.0000000e+001 3.0000000e-001 6.6000000e+000
1.0000000e+001 3.5000000e-001 7.7000000e+000
1.0000000e+001 4.0000000e-001 8.8000000e+000
1.0000000e+001 4.5000000e-001 9.9000000e+000
1.0000000e+001 5.0000000e-001 1.1000000e+001
1.0000000e+001 5.5000000e-001 1.2100000e+001
1.0000000e+001 6.0000000e-001 1.3200000e+001
1.0000000e+001 6.5000000e-001 1.4300000e+001
1.0000000e+001 7.0000000e-001 1.5400000e+001
1.0000000e+001 7.5000000e-001 1.6500000e+001
1.0000000e+001 8.0000000e-001 1.7600000e+001
1.0000000e+001 8.5000000e-001 1.8700000e+001
1.0000000e+001 9.0000000e-001 1.9800000e+001
1.0000000e+001 9.5000000e-001 2.0900000e+001
1.0000000e+001 1.0000000e+000 2.1425000e+001


Hi

Sorry, I was also confused here, my remark is related to parametric sweep multiple variable entries, where the first one must be strictly increasing and decresing. Your case is a bit more tricky, the error message is close and its more or less the same issue.

your text file has the first column set to 1, if this is used for the interpolation it is as if there are many settings for the same point. Either you have a coumn index error, or I have missed something also possible (I do not have access to matlab+3.5 from home)

--
Good luck
Ivar

how can I define a interpolation-based function f(t,x), which is time- and space-dependent (2024)

FAQs

What is an interpolating function? ›

In subject area: Engineering. In numerical mathematics, an approximation polynomial that is equal to the function it approximates at a number of specified stations or points is called an interpolation function. From: The Finite Element Method in Engineering (Fifth Edition), 2011.

What is the interpolation function in Comsol? ›

Interpolation Functions can be used to describe material properties that are defined by a table or file containing values of the function at discrete points. Either enter the data manually or import it from a data file. Then, specify the function behavior between data points and outside of your range of data.

How do you find the interpolation function? ›

The interpolation equation is as follows: y − y 1 = y 2 − y 1 x 2 − x 1 ( x − x 1 ) , where ( x 1 , y 1 ) and ( x 2 , y 2 ) are two known data points and ("x," "y") represents the data point to be estimated.

What is the interpolation method with an example? ›

In short, interpolation is a process of determining the unknown values that lie in between the known data points. It is mostly used to predict the unknown values for any geographical related data points such as noise level, rainfall, elevation, and so on.

Which function can be used for interpolation? ›

Interpolation, or estimating the value of that function for an intermediate value of the independent variable, is frequently necessary. Why polynomials are the most commonly used functions for interpolations: Because they are simple to evaluate, polynomials are the most often used interpolants.

What does an interpolation function represent? ›

interpolation, in mathematics, the determination or estimation of the value of f(x), or a function of x, from certain known values of the function. If x0 < … < xn and y0 = f(x0),…, yn = f(xn) are known, and if x0 < x < xn, then the estimated value of f(x) is said to be an interpolation.

How does interpolation work? ›

Interpolation means determining a value from the existing values in a given data set. Another way of describing it is the act of inserting or interjecting an intermediate value between two other values.

What does interpolate () do? ›

The interpolate() method replaces the NULL values based on a specified method.

What does interpolating mean in math? ›

In the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing (finding) new data points based on the range of a discrete set of known data points.

What is the interpolation formula used for? ›

Interpolation is a method of finding new values for any function using the set of values. We can determine the unknown value on a point using this formula. If linear interpolation formula is concerned then it can be used to find the new value from the two given points.

References

Top Articles
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6254

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.