need suggestion to calculate alpha value in semi-infinite experimental results

I wanted to solve for alpha by using experimental data for different time, the1, and the2.
Please suggest how to go ahead.
alpha=sym('alpha',[1 1467]);
eqn = (2*5761.11)*time.^0.5*(alpha).^0.5./(the1*pi^0.5)*exp((-x1^2)./(4*time.*alpha))-(5761.11*x1)./the1*(1-(2/sqrt(pi))*(x1./(2*sqrt(time.*alpha))-((x1./(2*sqrt(time.*alpha)))^3)/3))== (2*5761.11)*time.^0.5*(alpha).^0.5./(the2*pi^0.5)*exp((-x2^2)./(4*time.*alpha))-(5761.11*x2)./the2*(1-(2/sqrt(pi))*(x2./(2*sqrt(time.*alpha))-((x2./(2*sqrt(time.*alpha)))^3)/3));
Alpha = solve(eqn,alpha);

10 Comments

Your code doesn't run for scalar values of the variables you indicated. x1 is also undefined. Once your code runs for single values, it should be trivial to extend it to multiple values by making a function.
time=1;the1=2;the2=3;
x1=4;
alpha=sym('alpha',[1 1467]);
eqn = (2*5761.11)*time.^0.5*(alpha).^0.5./(the1*pi^0.5)*exp((-x1^2)./(4*time.*alpha))-(5761.11*x1)./the1*(1-(2/sqrt(pi))*(x1./(2*sqrt(time.*alpha))-((x1./(2*sqrt(time.*alpha)))^3)/3))== (2*5761.11)*time.^0.5*(alpha).^0.5./(the2*pi^0.5)*exp((-x2^2)./(4*time.*alpha))-(5761.11*x2)./the2*(1-(2/sqrt(pi))*(x2./(2*sqrt(time.*alpha))-((x2./(2*sqrt(time.*alpha)))^3)/3));
Error using *
Dimensions do not match.
Alpha = solve(eqn,alpha)
time is a vector the same size as alpha? Are the1 and the2 scalar or vector?
Yes. time, alpha, the1, the2 are all of the same size.
@Rik, I have solved for a single time, the1, the2, alpha.
I wanted to extend the same for all my experimental results.
Can you please suggest how to go ahead for multiple values?
If you post your code the edit will probably be fairly simple. As you can see, your current code actually does not work. At least it doesn't on R2022a, and since you didn't specify your release anywhere, you implied you are using a sufficiently new release that the Matlab version can't cause any issues.
@Rik, I have attached my code which is running.
6000 (time), 79.72195(the1), 76.38214(the2) - I need to be replaced with multiple values to get the corresponding values of alpha.
system x
eqn = (2*5761.11)*6000^0.5*(x)^0.5/(79.72195*pi^0.5)*exp((-0.01^2)/(4*x*6000))-(5761.11*0.01)/79.38214*(1-(2/sqrt(pi))*(0.01/(2*sqrt(x*6000))-((0.01/(2*sqrt(x*6000)))^3)/3))== (2*5761.11)*6000^0.5*(x)^0.5/(76.38214*pi^0.5)*exp((-0.03^2)/(4*x*6000))-(5761.11*0.03)/76.38214*(1-(2/sqrt(pi))*(0.03/(2*sqrt(x*6000))-((0.03/(2*sqrt(x*6000)))^3)/3));
S = solve(eqn,x)
Do you have some function or class that is called system? Because the normal system command calls the command line of the OS.
If you insert your code as a 'line of code' instead of 'code example' you will be able to run your code. You need to make sure it runs in the online environment. Then you can be certain that we can reproduce your efforts.
time=6000;
the1=79.72195;
th2=76.38214;
system x
/bin/bash: x: command not found
ans = 127
eqn = (2*5761.11)*6000^0.5*(x)^0.5/(79.72195*pi^0.5)*exp((-0.01^2)/(4*x*6000))-(5761.11*0.01)/79.38214*(1-(2/sqrt(pi))*(0.01/(2*sqrt(x*6000))-((0.01/(2*sqrt(x*6000)))^3)/3))== (2*5761.11)*6000^0.5*(x)^0.5/(76.38214*pi^0.5)*exp((-0.03^2)/(4*x*6000))-(5761.11*0.03)/76.38214*(1-(2/sqrt(pi))*(0.03/(2*sqrt(x*6000))-((0.03/(2*sqrt(x*6000)))^3)/3));
Unrecognized function or variable 'x'.
S = solve(eqn,x)
syms x instead of system x.
syms x
eqn = (2*5761.11)*6000^0.5*(x)^0.5/(79.72195*pi^0.5)*exp((-0.01^2)/(4*x*6000))-(5761.11*0.01)/79.38214*(1-(2/sqrt(pi))*(0.01/(2*sqrt(x*6000))-((0.01/(2*sqrt(x*6000)))^3)/3))== (2*5761.11)*6000^0.5*(x)^0.5/(76.38214*pi^0.5)*exp((-0.03^2)/(4*x*6000))-(5761.11*0.03)/76.38214*(1-(2/sqrt(pi))*(0.03/(2*sqrt(x*6000))-((0.03/(2*sqrt(x*6000)))^3)/3));
S = solve(eqn,x)
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
S = 
0.000029352683458310990175159943542835
Now you have code that works, but no longer contains your variables. Why did you do that? Now you have to go in and change that 6000 to the value of time, instead of changing the value of time.
You need to write code that runs in the online environment (use the green arrow) and that depends on your variables. You're almost there.

Sign in to comment.

Answers (1)

Hi Akshay,
It is my understanding that you are expecting an approach to solve for alpha using experimental data for different times (time), the1, and the2 which can be semi-infinite in number. You can follow these steps as an approach for the solution,
  1. Define the symbolic variable alpha using the sym function.
  2. Set up the equation (eqn) that relates alpha to the experimental data. Make sure to replace the variables in the equation with their corresponding values.
  3. Solve the equation (eqn) to find the values of alpha that satisfy the equation. The variable Alpha will contain the solutions for alpha based on the experimental data provided.
Please refer to the sample implementation given below,
function Alpha = solveAlpha(time_values, the1_values, the2_values)
syms alpha
Alpha = zeros(length(time_values), length(the1_values)); % Preallocate array to store results
for i = 1:length(time_values)
for j = 1:length(the1_values)
eqn = (2 * 5761.11) * time_values(i)^0.5 * (alpha)^0.5 / (the1_values(j) * pi^0.5) * exp((-x1^2) / (4 * time_values(i) * alpha)) - (5761.11 * x1) / the1_values(j) * (1 - (2 / sqrt(pi)) * (x1 / (2 * sqrt(time_values(i) * alpha)) - ((x1 / (2 * sqrt(time_values(i) * alpha)))^3) / 3)) == (2 * 5761.11) * time_values(i)^0.5 * (alpha)^0.5 / (the2_values(j) * pi^0.5) * exp((-x2^2) / (4 * time_values(i) * alpha)) - (5761.11 * x2) / the2_values(j) * (1 - (2 / sqrt(pi)) * (x2 / (2 * sqrt(time_values(i) * alpha)) - ((x2 / (2 * sqrt(time_values(i) * alpha)))^3) / 3));
solutions = solve(eqn, alpha);
Alpha(i, j) = double(solutions);
end
end
end
Make sure to replace x1 and x2 with the actual values you have for the variables. The nested loops will iterate over each combination of time, the1, and the2 values, solve the equation, and store the corresponding values of alpha in the Alpha matrix.
Hope you find it helpful.
Sandeep BS

Products

Asked:

on 14 Mar 2022

Answered:

on 26 Sep 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!