assume can't constrain vpasolve (2024)

2 views (last 30 days)

Show older comments

Faraz j on 4 Feb 2024

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve

Edited: Torsten on 6 Feb 2024

Accepted Answer: Torsten

Open in MATLAB Online

Hello,

I am attempting to solve a system of nonlinear equations, but unfortunately, vpasolve find answer outside the range I specified and also ignores the constrain condition using "assume".

Here is my code:

% ------------ Parameters --------------------

M = 2;

N = 4;

a = 22.3702/25.4;

beta_10 = 3.41;

k0 = 4.9348;

K2 = 493.2753;

V = [0.7509 1.0000 1.0000 0.7509];

Zb = [-13.0203-6.9290i -19.0747-10.8648i -38.1365-9.9235i -46.2847-14.8522i];

X = [0.1672 -0.2434 0.1502 -0.0871 ; 0.0871 -0.1502 0.2434 -0.1672];

% ------------ Required Functions --------------------

syms g(x) h1(y) h2(y) v(x)

g(x) = 1.177.*sin((pi.*x)./a).^2;

h1(y) = 1-275.*(y-1).^2;

h2(y) = -14.*(y-1);

h(y) = h1(y) + 1i*h2(y);

v(x) = 1.517+1.833.*x.^2;

% ------------ Equation Functions --------------------

x = sym('x',[M N]);

y = sym('y',[M N]);

E1 = []; E2 = []; E3 = []; eq3 = 0; eq4 = 0;

j = 1;

for i = 1:N

Fn = ((cos((beta_10/k0)*y(j,i)*v(x(j,i)))-cos(y(j,i)*v(x(j,i))))/sin(y(j,i)*v(x(j,i))))*(sin(pi*x(j,i))/a);

Ya_G0 = (K2*Fn^2) / (((K2*Fn^2)/(g(x(j,i))*h(y(j,i))))+(Zb(j,i)));

E1 = [E1; imag((K2*Fn^2)/(g(x(j,i))*h(y(j,i)))) == -1*imag(Zb(j,i))];

if i==1 && j==1

Fn_1 = Fn;

Ya_G0_1 = Ya_G0;

else

if mod(i-1,2) == 1

sign = -1;

else

sign = +1;

end

E2 = [E2; (Ya_G0/(Fn)) == (-1)^(j-1)*sign * abs(V(j,i)/V(1,1)) * (sin(y(j,i)*v(x(j,i)))/(sin(y(1,1)*v(x(1,1))))) * (Ya_G0_1/(Fn_1)) ];

end

eq3 = eq3 + Ya_G0;

end

E3 = [E3; eq3 == 2];

E = [E1.',E2.',E3.'];

assume(x,"real"); assumeAlso(x<0.48*a);

assume(y,"positive"); assumeAlso(y,"real");

X_T = X.';

X_trial = X_T(:).';

sol_initial = [X_trial(1:M*N/2),ones(1,M*N/2)];

% sol_range = [all_x_range(1:M*N/2,:);repmat([0.96 1.04],M*N/2,1)];

% sol_initial = sol_range;

x_T = x.'; x_unknown_vector = x_T(:).';

y_T = y.'; y_unknown_vector = y_T(:).';

unknown = [x_unknown_vector(1:M*N/2),y_unknown_vector(1:M*N/2)];

S = vpasolve(E,unknown,sol_initial);

MyFieldNames = fieldnames(S);

MyValuesX = zeros(1,M*N/2); MyValuesY = zeros(1,M*N/2);

for i=1:M*N/2

MyValuesX(1,i) = getfield(S,MyFieldNames{i});

MyValuesY(1,i) = getfield(S,MyFieldNames{i+N/2});

end

round(MyValuesY,3)

ans = 1×4

0.1500 -0.0870 1.0050 1.0070

I also used the range for "vpasolver" as commented "sol_range" in the above code, but I didn't get the desired result either.

The solution to "y" should be a number around 1.

Thanks for your help in advance.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#answer_1402511

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#answer_1402511

Moved: Torsten on 4 Feb 2024

vpasolve is a numerical solver - symbolic commands like "assume" are not respected. But you can set ranges for the variables in "vpasolve" by setting "init_param" to a numerical search interval.

6 Comments

Show 4 older commentsHide 4 older comments

Faraz j on 4 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053106

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053106

Open in MATLAB Online

I defined the range as

all_x_range = repmat([0 a/2;-a/2 0],M*N/2,1);

sol_range = [all_x_range(1:M*N/2,:);repmat([0.96 1.04],M*N/2,1)];

but still give me a solution outside of this range !!!!

Torsten on 4 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053306

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053306

Most probably, no solution for y in the specified range can be found.

Faraz j on 5 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053696

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053696

Edited: Faraz j on 5 Feb 2024

Open in MATLAB Online

This is the solution vpasolve should find !

MyValuesX = [0.167 -0.2434 0.1502 -0.0871];

MyValuesY = [1.005 1.007 1.0075 1.0114];

Torsten on 5 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053791

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053791

Edited: Torsten on 5 Feb 2024

Open in MATLAB Online

Ok, vpasolve failed.

Here is a numerical solution with "lsqnonlin":

% ------------ Parameters --------------------

M = 2;

a = 22.3702/25.4;

beta_10 = 3.41;

k0 = 4.9348;

K2 = 493.2753;

V = [0.7509 1.0000 1.0000 0.7509];

Zb = [-13.0203-6.9290i -19.0747-10.8648i -38.1365-9.9235i -46.2847-14.8522i];

X = [0.1672 -0.2434 0.1502 -0.0871 ; 0.0871 -0.1502 0.2434 -0.1672];

% ------------ Required Functions --------------------

syms g(x) h1(y) h2(y) v(x)

g(x) = 1.177.*sin((pi.*x)./a).^2;

h1(y) = 1-275.*(y-1).^2;

h2(y) = -14.*(y-1);

h(y) = h1(y) + 1i*h2(y);

v(x) = 1.517+1.833.*x.^2;

% ------------ Equation Functions --------------------

x = sym('x',[M N]);

y = sym('y',[M N]);

E1 = []; E2 = []; E3 = []; eq3 = 0; eq4 = 0;

j = 1;

for i = 1:N

Fn = ((cos((beta_10/k0)*y(j,i)*v(x(j,i)))-cos(y(j,i)*v(x(j,i))))/sin(y(j,i)*v(x(j,i))))*(sin(pi*x(j,i))/a);

Ya_G0 = (K2*Fn^2) / (((K2*Fn^2)/(g(x(j,i))*h(y(j,i))))+(Zb(j,i)));

E1 = [E1; imag((K2*Fn^2)/(g(x(j,i))*h(y(j,i)))) - (-1*imag(Zb(j,i)))];

if i==1 && j==1

Fn_1 = Fn;

Ya_G0_1 = Ya_G0;

else

if mod(i-1,2) == 1

sign = -1;

else

sign = +1;

end

tmp=(Ya_G0/(Fn)) -( (-1)^(j-1)*sign * abs(V(j,i)/V(1,1)) * (sin(y(j,i)*v(x(j,i)))/(sin(y(1,1)*v(x(1,1))))) * (Ya_G0_1/(Fn_1)) );

E2 = [E2; tmp ];

end

eq3 = eq3 + Ya_G0;

end

E3 = [E3; eq3 - 2];

E = [E1.',E2.',E3.'];

Enum = matlabFunction(E);

Enum = @(z)real(Enum(z(1),z(2),z(3),z(4),z(5),z(6),z(7),z(8)));

all_x_range = repmat([0 a/2;-a/2 0],M*N/2,1);

sol_range = [all_x_range(1:M*N/2,:);repmat([0.96 1.04],M*N/2,1)];

lb = sol_range(:,1);

ub = sol_range(:,2);

format long

solnum = lsqnonlin(Enum,(lb+ub)/2,lb,ub,optimset('TolX',1e-12,'TolFun',1e-12))

Local minimum possible.lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.

solnum = 8×1

0.167210839303176 -0.243345930008853 0.150185145920223 -0.087101777478330 1.005182169079357 1.007061443401629 1.007465052260141 1.011445713909488

Enum(solnum)

ans = 1×8

1.0e-12 * -0.071942451995710 0.156319401867222 0.099475983006414 -0.110134124042816 0 -0.000888178419700 -0.001554312234475 0.000444089209850

Faraz j on 6 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3054861

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3054861

Edited: Faraz j on 6 Feb 2024

Open in MATLAB Online

Thanks a lot ! you're life saver

One more issue @Torsten! for different M and N, how can I modify this

Enum = @(z)real(Enum(z(1),z(2),z(3),z(4),z(5),z(6),z(7),z(8)));

Torsten on 6 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3055721

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3055721

Edited: Torsten on 6 Feb 2024

Open in MATLAB Online

Enum = matlabFunction(E,'Vars',{[x(1,1:N),y(1,1:N)]})

Enum = @(z)real(Enum(z.'));

instead of

Enum = matlabFunction(E);

Enum = @(z)real(Enum(z(1),z(2),z(3),z(4),z(5),z(6),z(7),z(8)));

This is at least correct for the equations you solved above since j was not increased and remained 1 (so I don't know why you created x and y as x(M,N) and y(M,N) and not as x(1,N) and y(1,N))

Sign in to comment.

More Answers (1)

Matt J on 4 Feb 2024

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#answer_1402561

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#answer_1402561

Edited: Matt J on 4 Feb 2024

There doesn't appear to be any good reason for you to be using sym variables. Your code doesn't seem to make use of any other Symbolic Math Toolbox functions like diff or simplify.... Just re-implement using non-symbolic variables and solve with lsqnonlin which does allow you to impose bounds on the variables. Or, use matlabFunction to convert your symbolic functions into nonsymbolic ones.

3 Comments

Show 1 older commentHide 1 older comment

Faraz j on 5 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053721

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053721

Edited: Faraz j on 5 Feb 2024

Open in MATLAB Online

Thanks for your suggestion !

I wanted to try this approach, but building the function was complicated for me without knowing matlabFunction.

I am not good at this, I think. I tried this and got an error

fun = matlabFunction(E);

lsqnonlin(fun,sol_initial)

what am I doing wrong?

Matt J on 5 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053941

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3053941

what am I doing wrong?

Who knows? You haven't shown copy/pastes of the errors.

Faraz j on 6 Feb 2024

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3054866

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2078046-assume-can-t-constrain-vpasolve#comment_3054866

Thanks for your advice, @Torsten solved the issue !

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Mathematics and OptimizationSymbolic Math ToolboxSymbolic Computations in MATLABConversion Between Symbolic and Numeric

Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange

Tags

  • vpasolve
  • assume
  • equation
  • nonlinear
  • sym for no reason

Products

  • MATLAB

Release

R2020b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


assume can't constrain vpasolve (13)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

assume can't constrain vpasolve (2024)

FAQs

What does vpasolve mean in MATLAB? ›

An equation or a system of equations can have multiple solutions. To find these solutions numerically, use the function vpasolve . For polynomial equations, vpasolve returns all solutions. For nonpolynomial equations, vpasolve returns the first solution it finds.

What is the difference between solve and Vpasolve? ›

solve solves equations and inequalities that contain parameters. vpasolve does not solve inequalities, nor does it solve equations that contain parameters. solve can return parameterized solutions. vpasolve does not return parameterized solutions.

What is the precision of Vpasolve in MATLAB? ›

By default, vpasolve finds the solutions to 32 significant digits. To change the number of significant digits, use the digits function.

What is approximate solution in MATLAB? ›

approximate( solution ) generates either a Simulink® model containing a subsystem made up of the Lookup Table block, or a lookup table as a MATLAB® function, depending on the ApproximateSolutionType property of the FunctionApproximation.

What is VPA used for in MATLAB? ›

Description. xVpa = vpa( x ) uses variable-precision arithmetic (arbitrary-precision floating-point numbers) to evaluate each element of the symbolic input x to at least d significant digits, where d is the value of the digits function. The default value of digits is 32.

How to solve for a variable? ›

These are the general steps for solving an equation with variables:
  1. Step 1: Simplify both sides of the equation.
  2. Step 2: Move all of the parts containing the variable you are solving for to the same side of the equation.
  3. Step 3: Isolate the variable using inverse operations.
Dec 26, 2023

How do I fix precision in MATLAB? ›

You can set a higher precision by using the digits function. Approximate a sum using the default precision of 32 digits. If at least one input is wrapped with vpa , all other inputs are converted to variable precision automatically. You must wrap all inner inputs with vpa , such as exp(vpa(200)) .

How many decimal places is a VPA in MATLAB? ›

The default precision for vpa is 32 digits. Increase precision beyond 32 digits by using digits . Find pi using vpa , which uses the default 32 digits of precision. Confirm that the current precision is 32 by using digits .

How do you set MATLAB to double precision? ›

Description. Y = double( X ) converts the values in X to double precision.

What is the difference between exact solution and approximate solution? ›

My understanding is that "exact" translates to "produces a provably optimal solution" and "approximate" translates to "may or may not find an optimal solution but will not provide proof of optimality".

What is approximate answers? ›

An approximation is anything that is intentionally similar but not exactly equal to something else.

What does an approximate answer mean? ›

An approximation is anything that is similar, but not exactly equal, to something else. A number can be approximated by rounding.

What does Dsolve mean in MATLAB? ›

dsolve sorts the dependent variables alphabetically, and then assigns the solutions for the variables to output variables or symbolic arrays.

How does linsolve work in MATLAB? ›

X = linsolve( A , B ) solves the matrix equation AX = B, where A is a symbolic matrix and B is a symbolic column vector. [ X , R ] = linsolve( A , B ) also returns the reciprocal of the condition number of A if A is a square matrix. Otherwise, linsolve returns the rank of A .

How to use simplify in MATLAB? ›

S = simplify( expr ) performs algebraic simplification of expr . If expr is a symbolic vector or matrix, this function simplifies each element of expr . S = simplify( expr , Name,Value ) performs algebraic simplification of expr using additional options specified by one or more Name,Value pair arguments.

How to declare a variable in MATLAB? ›

Create Variables

You can create new variables in the workspace by running MATLAB code or using existing variables. You do not have to declare variables before assigning values to them. To view and edit variables, use the Workspace browser and Variables editor. (Some editing options are not available in MATLAB Online™.)

Top Articles
Clark County Ohio Land For Sale | Mossy Oak Properties- Page 28 -
Outlaw Rogue Stat Priority
Umbc Baseball Camp
Greedfall Console Commands
Explore Tarot: Your Ultimate Tarot Cheat Sheet for Beginners
Lexington Herald-Leader from Lexington, Kentucky
Red Wing Care Guide | Fat Buddha Store
More Apt To Complain Crossword
Www Thechristhospital Billpay
Ogeechee Tech Blackboard
Swimgs Yung Wong Travels Sophie Koch Hits 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Springs Cow Dog Pig Hollywood Studios Beach House Flying Fun Hot Air Balloons, Riding Lessons And Bikes Pack Both Up Away The Alpha Baa Baa Twinkle
The Wicked Lady | Rotten Tomatoes
Ladyva Is She Married
Voyeuragency
How Many Slices Are In A Large Pizza? | Number Of Pizzas To Order For Your Next Party
My.doculivery.com/Crowncork
Diablo 3 Metascore
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Best Suv In 2010
Sound Of Freedom Showtimes Near Cinelux Almaden Cafe & Lounge
bode - Bode frequency response of dynamic system
Outlet For The Thames Crossword
Sussur Bloom locations and uses in Baldur's Gate 3
Walmart Near South Lake Tahoe Ca
South Bend Weather Underground
Weve Got You Surrounded Meme
Elbert County Swap Shop
Renfield Showtimes Near Paragon Theaters - Coral Square
Local Collector Buying Old Motorcycles Z1 KZ900 KZ 900 KZ1000 Kawasaki - wanted - by dealer - sale - craigslist
11526 Lake Ave Cleveland Oh 44102
LG UN90 65" 4K Smart UHD TV - 65UN9000AUJ | LG CA
Tire Pro Candler
Weekly Math Review Q4 3
Panchitos Harlingen Tx
Movies123.Pick
Craigslist West Seneca
Shoreone Insurance A.m. Best Rating
KITCHENAID Tilt-Head Stand Mixer Set 4.8L (Blue) + Balmuda The Pot (White) 5KSM175PSEIC | 31.33% Off | Central Online
Bismarck Mandan Mugshots
Housing Intranet Unt
Top 25 E-Commerce Companies Using FedEx
Ursula Creed Datasheet
The Realreal Temporary Closure
Payrollservers.us Webclock
Petra Gorski Obituary (2024)
Stosh's Kolaches Photos
Iupui Course Search
The Bold and the Beautiful
Aznchikz
Osrs Vorkath Combat Achievements
Qvc Com Blogs
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 5889

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.